1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: allow for arr.any(opt_fn()?), add test

This commit is contained in:
Delyan Angelov 2022-04-09 19:50:03 +03:00
parent 58febe4607
commit df30b79971
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 13 additions and 0 deletions

View File

@ -1726,6 +1726,10 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ ast.Type, node ast
if is_map && arg_expr.return_type in [ast.void_type, 0] {
c.error('type mismatch, `$arg_expr.name` does not return anything', arg_expr.pos)
} else if !is_map && arg_expr.return_type != ast.bool_type {
if arg_expr.or_block.kind != .absent && arg_expr.return_type.has_flag(.optional)
&& arg_expr.return_type.clear_flag(.optional) == ast.bool_type {
return
}
c.error('type mismatch, `$arg_expr.name` must return a bool', arg_expr.pos)
}
}

View File

@ -30,3 +30,12 @@ fn test_array_eval_count() {
a4 = Counter{}
assert a4.new_arr('all() failed').all(it == 2) == false
}
fn opt_bool_fn() ?bool {
return true
}
fn test_any_called_with_opt_bool_fn() ? {
_ := [1, 2, 3].any(opt_bool_fn() ?)
assert true
}