checker: fix for_in_index type error
parent
ef46fbb96f
commit
c9b395f9cf
|
@ -1663,9 +1663,8 @@ fn (mut c Checker) stmt(node ast.Stmt) {
|
|||
scope.update_var_type(it.key_var, key_type)
|
||||
}
|
||||
value_type := c.table.value_type(typ)
|
||||
if value_type == table.void_type {
|
||||
typ_sym := c.table.get_type_symbol(typ)
|
||||
c.error('for in: cannot index `$typ_sym.name`', it.cond.position())
|
||||
if value_type == table.void_type || typ.has_flag(.optional) {
|
||||
c.error('for in: cannot index `${c.table.type_to_str(typ)}`', it.cond.position())
|
||||
}
|
||||
it.cond_type = typ
|
||||
it.kind = sym.kind
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/for_in_index_optional.v:3:18: error: for in: cannot index `?[]string`
|
||||
1 | import os
|
||||
2 | fn main() {
|
||||
3 | for file in os.ls('.') {
|
||||
| ~~~~~~~
|
||||
4 | println(file)
|
||||
5 | }
|
|
@ -0,0 +1,6 @@
|
|||
import os
|
||||
fn main() {
|
||||
for file in os.ls('.') {
|
||||
println(file)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
vlib/v/checker/tests/for-in-index-type.v:2:11: error: for in: cannot index `any_int`
|
||||
vlib/v/checker/tests/for_in_index_type.v:2:11: error: for in: cannot index `any_int`
|
||||
1 | fn main() {
|
||||
2 | for a in 52 {
|
||||
| ~~
|
Loading…
Reference in New Issue