mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
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
|
||||
high_expr := expr.high
|
||||
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()
|
||||
high = high_expr.val.i64()
|
||||
} else {
|
||||
c.error('mismatched range types', low_expr.pos)
|
||||
}
|
||||
} 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]
|
||||
high = high_expr.val[0]
|
||||
} else {
|
||||
|
7
vlib/v/checker/tests/match_range_mismatch_type_err.out
Normal file
7
vlib/v/checker/tests/match_range_mismatch_type_err.out
Normal file
@ -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 | }
|
11
vlib/v/checker/tests/match_range_mismatch_type_err.vv
Normal file
11
vlib/v/checker/tests/match_range_mismatch_type_err.vv
Normal file
@ -0,0 +1,11 @@
|
||||
fn main() {
|
||||
x := '1'
|
||||
match x {
|
||||
`0`...`9` {
|
||||
println('0-9')
|
||||
}
|
||||
else {
|
||||
println('!0-9')
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user