diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index 1677877f58ad38..27c2687475c6fa 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -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 { diff --git a/vlib/v/checker/tests/map_result_callback_fn_err.out b/vlib/v/checker/tests/map_result_callback_fn_err.out new file mode 100644 index 00000000000000..d15591c819d350 --- /dev/null +++ b/vlib/v/checker/tests/map_result_callback_fn_err.out @@ -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 | diff --git a/vlib/v/checker/tests/map_result_callback_fn_err.vv b/vlib/v/checker/tests/map_result_callback_fn_err.vv new file mode 100644 index 00000000000000..5403decbefe800 --- /dev/null +++ b/vlib/v/checker/tests/map_result_callback_fn_err.vv @@ -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 +}