mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: improve mismatched range types error messages
This commit is contained in:
parent
fda39bfb82
commit
a3b60e6b55
@ -162,7 +162,8 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
|
|||||||
c.error('start value is higher than end value', branch.pos)
|
c.error('start value is higher than end value', branch.pos)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.error('mismatched range types', low_expr.pos)
|
c.error('mismatched range types - $expr.low is an integer, but $expr.high is not',
|
||||||
|
low_expr.pos)
|
||||||
}
|
}
|
||||||
} else if low_expr is ast.CharLiteral {
|
} else if low_expr is ast.CharLiteral {
|
||||||
if high_expr is ast.CharLiteral && final_cond_sym.kind in [.u8, .char, .rune] {
|
if high_expr is ast.CharLiteral && final_cond_sym.kind in [.u8, .char, .rune] {
|
||||||
@ -172,7 +173,9 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
|
|||||||
c.error('start value is higher than end value', branch.pos)
|
c.error('start value is higher than end value', branch.pos)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.error('mismatched range types', low_expr.pos)
|
typ := c.table.type_to_str(c.expr(node.cond))
|
||||||
|
c.error('mismatched range types - trying to match `$node.cond`, which has type `$typ`, to a range of `rune`',
|
||||||
|
low_expr.pos)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
typ := c.table.type_to_str(c.expr(expr.low))
|
typ := c.table.type_to_str(c.expr(expr.low))
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
vlib/v/checker/tests/match_range_mismatch_type_err.vv:4:3: error: mismatched range types
|
vlib/v/checker/tests/match_range_mismatch_type_err.vv:4:3: error: mismatched range types - trying to match `x`, which has type `string`, to a range of `rune`
|
||||||
2 | x := '1'
|
2 | x := '1'
|
||||||
3 | match x {
|
3 | match x {
|
||||||
4 | `0`...`9` {
|
4 | `0`...`9` {
|
||||||
| ~~~
|
| ~~~
|
||||||
5 | println('0-9')
|
5 | println('0-9')
|
||||||
6 | }
|
6 | }
|
||||||
|
vlib/v/checker/tests/match_range_mismatch_type_err.vv:16:3: error: mismatched range types - 0 is an integer, but `9` is not
|
||||||
|
14 | x := 1
|
||||||
|
15 | match x {
|
||||||
|
16 | 0...`9` {}
|
||||||
|
| ^
|
||||||
|
17 | else {}
|
||||||
|
18 | }
|
||||||
|
@ -9,3 +9,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn abc() {
|
||||||
|
x := 1
|
||||||
|
match x {
|
||||||
|
0...`9` {}
|
||||||
|
else {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user