checker: allow for `arr.any(opt_fn()?)`, add test
parent
58febe4607
commit
df30b79971
|
@ -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] {
|
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)
|
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 {
|
} 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)
|
c.error('type mismatch, `$arg_expr.name` must return a bool', arg_expr.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,3 +30,12 @@ fn test_array_eval_count() {
|
||||||
a4 = Counter{}
|
a4 = Counter{}
|
||||||
assert a4.new_arr('all() failed').all(it == 2) == false
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue