mirror of
https://github.com/vlang/v.git
synced 2025-09-10 16:00:31 -04:00
This commit is contained in:
parent
856984aa14
commit
d912268e5d
@ -300,6 +300,7 @@ fn (mut c Checker) get_comptime_number_value(mut expr ast.Expr) ?i64 {
|
|||||||
fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSymbol) {
|
fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSymbol) {
|
||||||
c.expected_type = node.expected_type
|
c.expected_type = node.expected_type
|
||||||
cond_sym := c.table.sym(node.cond_type)
|
cond_sym := c.table.sym(node.cond_type)
|
||||||
|
mut enum_ref_checked := false
|
||||||
// branch_exprs is a histogram of how many times
|
// branch_exprs is a histogram of how many times
|
||||||
// an expr was used in the match
|
// an expr was used in the match
|
||||||
mut branch_exprs := map[string]int{}
|
mut branch_exprs := map[string]int{}
|
||||||
@ -385,6 +386,13 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
|
|||||||
}
|
}
|
||||||
ast.EnumVal {
|
ast.EnumVal {
|
||||||
key = expr.val
|
key = expr.val
|
||||||
|
if !enum_ref_checked {
|
||||||
|
enum_ref_checked = true
|
||||||
|
if node.cond_type.is_ptr() {
|
||||||
|
c.error('missing `*` dereferencing `${node.cond}` in match statement',
|
||||||
|
node.cond.pos())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
key = (*expr).str()
|
key = (*expr).str()
|
||||||
|
7
vlib/v/checker/tests/match_enum_ref.out
Normal file
7
vlib/v/checker/tests/match_enum_ref.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
vlib/v/checker/tests/match_enum_ref.vv:6:3: error: missing `*` dereferencing `t` in match statement
|
||||||
|
4 | fn f(t &SomeType) ?int {
|
||||||
|
5 | return match
|
||||||
|
6 | t // note the missing asterisk
|
||||||
|
| ^
|
||||||
|
7 | {
|
||||||
|
8 | .a {
|
18
vlib/v/checker/tests/match_enum_ref.vv
Normal file
18
vlib/v/checker/tests/match_enum_ref.vv
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
enum SomeType {
|
||||||
|
a
|
||||||
|
}
|
||||||
|
fn f(t &SomeType) ?int {
|
||||||
|
return match
|
||||||
|
t // note the missing asterisk
|
||||||
|
{
|
||||||
|
.a {
|
||||||
|
panic('This does not happen!')
|
||||||
|
3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
t := SomeType.a
|
||||||
|
f(&t)?
|
||||||
|
assert false // should not happen, but does
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user