mirror of
https://github.com/vlang/v.git
synced 2025-09-15 02:18:47 -04:00
checker: require else
branch in [flag]
enum match (#19375)
This commit is contained in:
parent
74d80a5120
commit
be53b02511
@ -396,6 +396,9 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
|
||||
unhandled << '`.${v}`'
|
||||
}
|
||||
}
|
||||
if cond_type_sym.info.is_flag {
|
||||
is_exhaustive = false
|
||||
}
|
||||
}
|
||||
else {
|
||||
is_exhaustive = false
|
||||
|
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/flag_enum_exhaustive_else_branch.vv:11:1: error: match must be exhaustive (add `else {}` at the end)
|
||||
9 | dump(perm)
|
||||
10 |
|
||||
11 | match perm {
|
||||
| ~~~~~~~~~~~~
|
||||
12 | .read { println('r') }
|
||||
13 | .write { println('w') }
|
16
vlib/v/checker/tests/flag_enum_exhaustive_else_branch.vv
Normal file
16
vlib/v/checker/tests/flag_enum_exhaustive_else_branch.vv
Normal file
@ -0,0 +1,16 @@
|
||||
[flag]
|
||||
enum Permission {
|
||||
read
|
||||
write
|
||||
execute
|
||||
}
|
||||
|
||||
perm := Permission.read | Permission.write | Permission.execute
|
||||
dump(perm)
|
||||
|
||||
match perm {
|
||||
.read { println('r') }
|
||||
.write { println('w') }
|
||||
.execute { println('x') }
|
||||
// must require an `else` here
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user