parser: forbid empty match statements 'match cond.op {else {}}' (#12618)
parent
6749979534
commit
8ac7739db8
|
@ -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
|
2 | a := 1
|
||||||
3 | match a {
|
3 | match a {
|
||||||
4 | else { println('abc') }
|
4 | else { println('abc') }
|
||||||
| ~~~~
|
| ~~~~
|
||||||
5 | }
|
5 | }
|
||||||
6 | println('hello')
|
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 {
|
|
||||||
|
|
|
@ -250,7 +250,7 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||||
scope: branch_scope
|
scope: branch_scope
|
||||||
}
|
}
|
||||||
if is_else && branches.len == 1 {
|
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) {
|
if p.tok.kind == .rcbr || (is_else && no_lcbr) {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue