@@ -2983,8 +2983,8 @@ fn (mut c Checker) check_predicate_param(is_map bool, elem_typ ast.Type, node as
29832983 // Finish early so that it doesn't fail later
29842984 return
29852985 }
2986- arg_expr := node.args[0 ].expr
2987- match arg_expr {
2986+ mut arg_expr := node.args[0 ].expr
2987+ match mut arg_expr {
29882988 ast.AnonFn {
29892989 if arg_expr.decl.return_type.has_flag (.option) {
29902990 c.error ('option needs to be unwrapped before using it in map/filter' ,
@@ -3024,7 +3024,7 @@ fn (mut c Checker) check_predicate_param(is_map bool, elem_typ ast.Type, node as
30243024 arg_expr.pos)
30253025 }
30263026 } else if arg_expr.kind == .variable {
3027- if arg_expr.obj is ast.Var {
3027+ if mut arg_expr.obj is ast.Var {
30283028 expr := arg_expr.obj.expr
30293029 if expr is ast.AnonFn {
30303030 // copied from above
@@ -3084,13 +3084,18 @@ fn (mut c Checker) check_predicate_param(is_map bool, elem_typ ast.Type, node as
30843084 }
30853085 }
30863086 ast.LambdaExpr {
3087- if arg_expr.expr is ast.CallExpr && is_map
3087+ if mut arg_expr.expr is ast.CallExpr && is_map
30883088 && arg_expr.expr.return_type in [ast.void_type, 0 ] {
30893089 c.error ('type mismatch, `${arg_expr.expr.name} ` does not return anything' ,
30903090 arg_expr.expr.pos)
30913091 }
30923092 }
3093- else {}
3093+ else {
3094+ if ! is_map && c.expr (mut arg_expr) != ast.bool_type {
3095+ c.error ('invalid expression, expected infix expr, lambda or function' ,
3096+ arg_expr.pos ())
3097+ }
3098+ }
30943099 }
30953100}
30963101
0 commit comments