diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 0eac696069..b6cc5cfeaa 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -5206,6 +5206,7 @@ pub fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { // since it is used in c.match_exprs() it saves checking twice node.cond_type = c.table.mktyp(cond_type) c.ensure_type_exists(node.cond_type, node.pos) or { return ast.void_type } + c.check_expr_opt_call(node.cond, cond_type) cond_type_sym := c.table.get_type_symbol(cond_type) if cond_type_sym.kind !in [.interface_, .sum_type] { node.is_sum_type = false diff --git a/vlib/v/checker/tests/optional_fn_err.out b/vlib/v/checker/tests/optional_fn_err.out index 7c889dfbaf..3e47b49b7b 100644 --- a/vlib/v/checker/tests/optional_fn_err.out +++ b/vlib/v/checker/tests/optional_fn_err.out @@ -151,10 +151,18 @@ vlib/v/checker/tests/optional_fn_err.vv:69:18: error: bar() returns an option, s 69 | println(arr.any(bar(true))) | ~~~~~~~~~ 70 | println(arr.all(bar(true))) - 71 | } + 71 | vlib/v/checker/tests/optional_fn_err.vv:70:18: error: bar() returns an option, so it should have either an `or {}` block, or `?` at the end 68 | println(arr.filter(bar(true))) 69 | println(arr.any(bar(true))) 70 | println(arr.all(bar(true))) | ~~~~~~~~~ - 71 | } + 71 | + 72 | match bar(0) { +vlib/v/checker/tests/optional_fn_err.vv:72:8: error: bar() returns an option, so it should have either an `or {}` block, or `?` at the end + 70 | println(arr.all(bar(true))) + 71 | + 72 | match bar(0) { + | ~~~~~~ + 73 | 0 { } + 74 | else { } diff --git a/vlib/v/checker/tests/optional_fn_err.vv b/vlib/v/checker/tests/optional_fn_err.vv index 90518a8360..b3d82d131d 100644 --- a/vlib/v/checker/tests/optional_fn_err.vv +++ b/vlib/v/checker/tests/optional_fn_err.vv @@ -68,4 +68,9 @@ fn main() { println(arr.filter(bar(true))) println(arr.any(bar(true))) println(arr.all(bar(true))) + + match bar(0) { + 0 { } + else { } + } }