From 8ac7739db8120853574ee80ff9ddf1b1801bbc95 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 30 Nov 2021 08:32:48 +0100 Subject: [PATCH] parser: forbid empty match statements 'match cond.op {else {}}' (#12618) --- vlib/v/checker/tests/return_missing_match_simple.out | 7 +------ vlib/v/parser/if_match.v | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/vlib/v/checker/tests/return_missing_match_simple.out b/vlib/v/checker/tests/return_missing_match_simple.out index 6e8306b603..7322173857 100644 --- a/vlib/v/checker/tests/return_missing_match_simple.out +++ b/vlib/v/checker/tests/return_missing_match_simple.out @@ -1,12 +1,7 @@ -vlib/v/checker/tests/return_missing_match_simple.vv:4:3: warning: `match` must have at least one non `else` branch +vlib/v/checker/tests/return_missing_match_simple.vv:4:3: error: `match` must have at least one non `else` branch 2 | a := 1 3 | match a { 4 | else { println('abc') } | ~~~~ 5 | } 6 | println('hello') -vlib/v/checker/tests/return_missing_match_simple.vv:1:1: error: missing return at end of function `h` - 1 | fn h() int { - | ~~~~~~~~~~ - 2 | a := 1 - 3 | match a { diff --git a/vlib/v/parser/if_match.v b/vlib/v/parser/if_match.v index 98087d24a0..2ad526fc5a 100644 --- a/vlib/v/parser/if_match.v +++ b/vlib/v/parser/if_match.v @@ -250,7 +250,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr { scope: branch_scope } if is_else && branches.len == 1 { - p.warn_with_pos('`match` must have at least one non `else` branch', pos) + p.error_with_pos('`match` must have at least one non `else` branch', pos) } if p.tok.kind == .rcbr || (is_else && no_lcbr) { break