mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix for in range type mismatch
This commit is contained in:
@@ -1105,6 +1105,16 @@ fn (c mut Checker) stmt(node ast.Stmt) {
|
|||||||
c.in_for_count++
|
c.in_for_count++
|
||||||
typ := c.expr(it.cond)
|
typ := c.expr(it.cond)
|
||||||
if it.is_range {
|
if it.is_range {
|
||||||
|
high_type := c.expr(it.high)
|
||||||
|
if typ in table.integer_type_idxs && high_type !in table.integer_type_idxs {
|
||||||
|
c.error('range types do not match', it.cond.position())
|
||||||
|
} else if typ in table.float_type_idxs || high_type in table.float_type_idxs {
|
||||||
|
c.error('range type can not be float', it.cond.position())
|
||||||
|
} else if typ == table.bool_type_idx || high_type == table.bool_type_idx {
|
||||||
|
c.error('range type can not be bool', it.cond.position())
|
||||||
|
} else if typ == table.string_type_idx || high_type == table.string_type_idx {
|
||||||
|
c.error('range type can not be string', it.cond.position())
|
||||||
|
}
|
||||||
c.expr(it.high)
|
c.expr(it.high)
|
||||||
} else {
|
} else {
|
||||||
mut scope := c.file.scope.innermost(it.pos.pos)
|
mut scope := c.file.scope.innermost(it.pos.pos)
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/inout/for_in_range_not_match_type.v:2:11: error: range types do not match
|
||||||
|
1| fn main() {
|
||||||
|
2| for i in 10..10.5 {
|
||||||
|
~~
|
||||||
|
3| println(i)
|
||||||
|
4| }
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fn main() {
|
||||||
|
for i in 10..10.5 {
|
||||||
|
println(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
6
vlib/v/checker/tests/inout/for_in_range_string_type.out
Normal file
6
vlib/v/checker/tests/inout/for_in_range_string_type.out
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
vlib/v/checker/tests/inout/for_in_range_string_type.v:2:11: error: range type can not be string
|
||||||
|
1| fn main() {
|
||||||
|
2| for i in 'a'..'b' {
|
||||||
|
~~~
|
||||||
|
3| println(i)
|
||||||
|
4| }
|
||||||
5
vlib/v/checker/tests/inout/for_in_range_string_type.vv
Normal file
5
vlib/v/checker/tests/inout/for_in_range_string_type.vv
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
fn main() {
|
||||||
|
for i in 'a'..'b' {
|
||||||
|
println(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user