mirror of
https://github.com/vlang/v.git
synced 2025-09-12 17:07:11 -04:00
checker: disallow none
as match cond (#20688)
This commit is contained in:
parent
1dc5d36724
commit
74d4081f1b
@ -59,6 +59,9 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
|
||||
c.error('`match` expression with Option type only checks against `none`, to match its value you must unwrap it first `var?`',
|
||||
branch.pos)
|
||||
}
|
||||
if cond_type_sym.kind == .none_ {
|
||||
c.error('`none` cannot be a match condition', node.pos)
|
||||
}
|
||||
// If the last statement is an expression, return its type
|
||||
if branch.stmts.len > 0 {
|
||||
mut stmt := branch.stmts.last()
|
||||
|
5
vlib/v/checker/tests/none_match_cond_err.out
Normal file
5
vlib/v/checker/tests/none_match_cond_err.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/none_match_cond_err.vv:1:1: error: `none` cannot be a match condition
|
||||
1 | match none {
|
||||
| ~~~~~~~~~~~~
|
||||
2 | none {}
|
||||
3 | else {}
|
4
vlib/v/checker/tests/none_match_cond_err.vv
Normal file
4
vlib/v/checker/tests/none_match_cond_err.vv
Normal file
@ -0,0 +1,4 @@
|
||||
match none {
|
||||
none {}
|
||||
else {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user