parent
724942c4e6
commit
48e65a7bb2
|
@ -6232,14 +6232,15 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
|
||||||
low_expr := expr.low
|
low_expr := expr.low
|
||||||
high_expr := expr.high
|
high_expr := expr.high
|
||||||
if low_expr is ast.IntegerLiteral {
|
if low_expr is ast.IntegerLiteral {
|
||||||
if high_expr is ast.IntegerLiteral {
|
if high_expr is ast.IntegerLiteral
|
||||||
|
&& (cond_type_sym.is_int() || cond_type_sym.info is ast.Enum) {
|
||||||
low = low_expr.val.i64()
|
low = low_expr.val.i64()
|
||||||
high = high_expr.val.i64()
|
high = high_expr.val.i64()
|
||||||
} else {
|
} else {
|
||||||
c.error('mismatched range types', low_expr.pos)
|
c.error('mismatched range types', low_expr.pos)
|
||||||
}
|
}
|
||||||
} else if low_expr is ast.CharLiteral {
|
} else if low_expr is ast.CharLiteral {
|
||||||
if high_expr is ast.CharLiteral {
|
if high_expr is ast.CharLiteral && cond_type_sym.kind in [.byte, .char, .rune] {
|
||||||
low = low_expr.val[0]
|
low = low_expr.val[0]
|
||||||
high = high_expr.val[0]
|
high = high_expr.val[0]
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/checker/tests/match_range_mismatch_type_err.vv:4:3: error: mismatched range types
|
||||||
|
2 | x := '1'
|
||||||
|
3 | match x {
|
||||||
|
4 | `0`...`9` {
|
||||||
|
| ~~~
|
||||||
|
5 | println('0-9')
|
||||||
|
6 | }
|
|
@ -0,0 +1,11 @@
|
||||||
|
fn main() {
|
||||||
|
x := '1'
|
||||||
|
match x {
|
||||||
|
`0`...`9` {
|
||||||
|
println('0-9')
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
println('!0-9')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue