mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add error for .map() calling a fn with multiple return values (prevent inaccessible tuple leak)
This commit is contained in:
@@ -1707,6 +1707,10 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
||||
else { arg_type }
|
||||
}
|
||||
node.return_type = c.table.find_or_register_array(c.unwrap_generic(ret_type))
|
||||
ret_sym := c.table.sym(ret_type)
|
||||
if ret_sym.kind == .multi_return {
|
||||
c.error('returning multiple values is not supported in .map() calls', node.pos)
|
||||
}
|
||||
} else if method_name == 'filter' {
|
||||
// check fn
|
||||
c.check_map_and_filter(false, elem_typ, node)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/map_func_return_multiple_values_err.vv:6:17: error: returning multiple values is not supported in .map() calls
|
||||
4 |
|
||||
5 | fn main() {
|
||||
6 | a := [1, 2, 3].map(fun)
|
||||
| ~~~~~~~~
|
||||
7 | println(a)
|
||||
8 | }
|
||||
@@ -0,0 +1,8 @@
|
||||
fn fun(n int) (int, string) {
|
||||
return n, n.str()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a := [1, 2, 3].map(fun)
|
||||
println(a)
|
||||
}
|
||||
Reference in New Issue
Block a user