mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add a warning if start value is higher than end value (#12602)
This commit is contained in:
parent
5786dd84e6
commit
9c88317ca6
@ -6365,6 +6365,9 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
|
||||
&& (cond_type_sym.is_int() || cond_type_sym.info is ast.Enum) {
|
||||
low = low_expr.val.i64()
|
||||
high = high_expr.val.i64()
|
||||
if low > high {
|
||||
c.error('start value is higher than end value', branch.pos)
|
||||
}
|
||||
} else {
|
||||
c.error('mismatched range types', low_expr.pos)
|
||||
}
|
||||
@ -6372,6 +6375,9 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
|
||||
if high_expr is ast.CharLiteral && cond_type_sym.kind in [.byte, .char, .rune] {
|
||||
low = low_expr.val[0]
|
||||
high = high_expr.val[0]
|
||||
if low > high {
|
||||
c.error('start value is higher than end value', branch.pos)
|
||||
}
|
||||
} else {
|
||||
c.error('mismatched range types', low_expr.pos)
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/match_expr_range_low_higher_than_high.vv:5:3: error: start value is higher than end value
|
||||
3 | value := 10
|
||||
4 | match value {
|
||||
5 | 20...10 {}
|
||||
| ~~~~~~~
|
||||
6 | else {}
|
||||
7 | }
|
@ -0,0 +1,8 @@
|
||||
|
||||
fn main() {
|
||||
value := 10
|
||||
match value {
|
||||
20...10 {}
|
||||
else {}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user