checker: check for_in_map using one variable error
parent
10da871743
commit
85723e3799
|
@ -1472,6 +1472,9 @@ fn (mut c Checker) stmt(node ast.Stmt) {
|
|||
} else {
|
||||
mut scope := c.file.scope.innermost(it.pos.pos)
|
||||
sym := c.table.get_type_symbol(typ)
|
||||
if sym.kind == .map && !(it.key_var.len > 0 && it.val_var.len > 0) {
|
||||
c.error('for in: cannot use one variable in map', it.pos)
|
||||
}
|
||||
if it.key_var.len > 0 {
|
||||
key_type := match sym.kind {
|
||||
.map { sym.map_info().key_type }
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
vlib/v/checker/tests/for_in_map_one_variable_err.v:3:6: error: for in: cannot use one variable in map
|
||||
1 | fn main() {
|
||||
2 | kvs := {'foo':'bar'}
|
||||
3 | for k in kvs {
|
||||
| ^
|
||||
4 | println('$k')
|
||||
5 | }
|
|
@ -0,0 +1,6 @@
|
|||
fn main() {
|
||||
kvs := {'foo':'bar'}
|
||||
for k in kvs {
|
||||
println('$k')
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue