diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index 57affaa817..b52e4983ef 100644 --- a/vlib/v/checker/match.v +++ b/vlib/v/checker/match.v @@ -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() diff --git a/vlib/v/checker/tests/none_match_cond_err.out b/vlib/v/checker/tests/none_match_cond_err.out new file mode 100644 index 0000000000..9853c66e45 --- /dev/null +++ b/vlib/v/checker/tests/none_match_cond_err.out @@ -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 {} diff --git a/vlib/v/checker/tests/none_match_cond_err.vv b/vlib/v/checker/tests/none_match_cond_err.vv new file mode 100644 index 0000000000..85ad2b7ec7 --- /dev/null +++ b/vlib/v/checker/tests/none_match_cond_err.vv @@ -0,0 +1,4 @@ +match none { + none {} + else {} +}