mirror of
https://github.com/vlang/v.git
synced 2025-09-17 11:26:17 -04:00
checker: disallow Result
callbacks functions like map/filter/all/any
(#21055)
This commit is contained in:
parent
a6087d01a2
commit
d5517b5b36
@ -2742,6 +2742,11 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ ast.Type, node ast
|
||||
}
|
||||
c.error('type mismatch, `${arg_expr.name}` must return a bool', arg_expr.pos)
|
||||
}
|
||||
if arg_expr.return_type.has_flag(.result) && arg_expr.or_block.kind != .block {
|
||||
if arg_expr.return_type.clear_option_and_result() in [ast.void_type, 0] {
|
||||
c.error('cannot use Result type in `${node.name}`', arg_expr.pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
ast.StringLiteral, ast.StringInterLiteral {
|
||||
if !is_map {
|
||||
|
7
vlib/v/checker/tests/map_result_callback_fn_err.out
Normal file
7
vlib/v/checker/tests/map_result_callback_fn_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/map_result_callback_fn_err.vv:19:17: error: cannot use Result type in `map`
|
||||
17 | threads << spawn update(den)
|
||||
18 | }
|
||||
19 | threads.map(it.wait()!)
|
||||
| ~~~~~~~
|
||||
20 | }
|
||||
21 |
|
25
vlib/v/checker/tests/map_result_callback_fn_err.vv
Normal file
25
vlib/v/checker/tests/map_result_callback_fn_err.vv
Normal file
@ -0,0 +1,25 @@
|
||||
import os
|
||||
import cli
|
||||
import net.urllib
|
||||
|
||||
pub fn sync() cli.Command {
|
||||
return cli.Command{
|
||||
name: 'sync'
|
||||
description: 'sync local dens from remote'
|
||||
execute: execsync
|
||||
}
|
||||
}
|
||||
|
||||
fn execsync(cmd cli.Command) ! {
|
||||
dens := os.read_lines('/etc/fox/dens')!.map(urllib.parse(it)!)
|
||||
mut threads := []thread !{}
|
||||
for den in dens {
|
||||
threads << spawn update(den)
|
||||
}
|
||||
threads.map(it.wait()!)
|
||||
}
|
||||
|
||||
fn update(den urllib.URL) ! {
|
||||
println(den.str())
|
||||
return
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user