diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index c473e9fc90..9056b7a41a 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -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) } } diff --git a/vlib/v/tests/array_methods_test.v b/vlib/v/tests/array_methods_test.v index f6dce7cdf6..d36017f2ae 100644 --- a/vlib/v/tests/array_methods_test.v +++ b/vlib/v/tests/array_methods_test.v @@ -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 +}