mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: add a warning for only else branch in match (#8185)
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
vlib/v/checker/tests/return_missing_match_simple.vv:4:3: warning: `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 {
|
||||
| ~~~~~~~~~~
|
||||
|
||||
@@ -247,6 +247,9 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||
post_comments: post_comments
|
||||
scope: branch_scope
|
||||
}
|
||||
if is_else && branches.len == 1 {
|
||||
p.warn_with_pos('`match` must have at least one non `else` branch', pos)
|
||||
}
|
||||
if p.tok.kind == .rcbr || (is_else && no_lcbr) {
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user