mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add check for call expr in map/filter (#9559)
This commit is contained in:
parent
7385f8e56b
commit
d8efe249ce
7
main.v
Normal file
7
main.v
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
list := [1,2,3].filter(stringsss(it))
|
||||
}
|
||||
|
||||
fn stringsss(arg int) string {
|
||||
return ''
|
||||
}
|
@ -1409,6 +1409,13 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ ast.Type, call_exp
|
||||
}
|
||||
}
|
||||
}
|
||||
ast.CallExpr {
|
||||
if is_map && arg_expr.return_type == table.void_type {
|
||||
c.error('type mismatch, `$arg_expr.name` does not return anything', arg_expr.pos)
|
||||
} else if !is_map && arg_expr.return_type != table.bool_type {
|
||||
c.error('type mismatch, `$arg_expr.name` must return a bool', arg_expr.pos)
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
||||
|
6
vlib/v/checker/tests/filter_func_return_nonbool_err.out
Normal file
6
vlib/v/checker/tests/filter_func_return_nonbool_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/filter_func_return_nonbool_err.vv:2:25: error: type mismatch, `stringsss` must return a bool
|
||||
1 | fn main() {
|
||||
2 | list := [1,2,3].filter(stringsss(it))
|
||||
| ~~~~~~~~~~~~~
|
||||
3 | }
|
||||
4 |
|
7
vlib/v/checker/tests/filter_func_return_nonbool_err.vv
Normal file
7
vlib/v/checker/tests/filter_func_return_nonbool_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
list := [1,2,3].filter(stringsss(it))
|
||||
}
|
||||
|
||||
fn stringsss(arg int) string {
|
||||
return ''
|
||||
}
|
6
vlib/v/checker/tests/map_func_void_return_err.out
Normal file
6
vlib/v/checker/tests/map_func_void_return_err.out
Normal file
@ -0,0 +1,6 @@
|
||||
vlib/v/checker/tests/map_func_void_return_err.vv:2:22: error: type mismatch, `voids` does not return anything
|
||||
1 | fn main() {
|
||||
2 | list := [1,2,3].map(voids(it))
|
||||
| ~~~~~~~~~
|
||||
3 | }
|
||||
4 |
|
7
vlib/v/checker/tests/map_func_void_return_err.vv
Normal file
7
vlib/v/checker/tests/map_func_void_return_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
list := [1,2,3].map(voids(it))
|
||||
}
|
||||
|
||||
fn voids(arg int) {
|
||||
println(arg)
|
||||
}
|
Loading…
Reference in New Issue
Block a user