Skip to content

Commit 74d4081

Browse files
authored
checker: disallow none as match cond (#20688)
1 parent 1dc5d36 commit 74d4081

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

vlib/v/checker/match.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
5959
c.error('`match` expression with Option type only checks against `none`, to match its value you must unwrap it first `var?`',
6060
branch.pos)
6161
}
62+
if cond_type_sym.kind == .none_ {
63+
c.error('`none` cannot be a match condition', node.pos)
64+
}
6265
// If the last statement is an expression, return its type
6366
if branch.stmts.len > 0 {
6467
mut stmt := branch.stmts.last()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vlib/v/checker/tests/none_match_cond_err.vv:1:1: error: `none` cannot be a match condition
2+
1 | match none {
3+
| ~~~~~~~~~~~~
4+
2 | none {}
5+
3 | else {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
match none {
2+
none {}
3+
else {}
4+
}

0 commit comments

Comments
 (0)