parser: forbid empty match statements 'match cond.op {else {}}' (#12618)

pull/12625/head
pancake 2021-11-30 08:32:48 +01:00 committed by GitHub
parent 6749979534
commit 8ac7739db8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 7 deletions

View File

@ -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 {

View File

@ -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