mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check for_in_map using one variable error
This commit is contained in:
parent
10da871743
commit
85723e3799
@ -1472,6 +1472,9 @@ fn (mut c Checker) stmt(node ast.Stmt) {
|
|||||||
} else {
|
} else {
|
||||||
mut scope := c.file.scope.innermost(it.pos.pos)
|
mut scope := c.file.scope.innermost(it.pos.pos)
|
||||||
sym := c.table.get_type_symbol(typ)
|
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 {
|
if it.key_var.len > 0 {
|
||||||
key_type := match sym.kind {
|
key_type := match sym.kind {
|
||||||
.map { sym.map_info().key_type }
|
.map { sym.map_info().key_type }
|
||||||
|
7
vlib/v/checker/tests/for_in_map_one_variable_err.out
Normal file
7
vlib/v/checker/tests/for_in_map_one_variable_err.out
Normal file
@ -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 | }
|
6
vlib/v/checker/tests/for_in_map_one_variable_err.vv
Normal file
6
vlib/v/checker/tests/for_in_map_one_variable_err.vv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
fn main() {
|
||||||
|
kvs := {'foo':'bar'}
|
||||||
|
for k in kvs {
|
||||||
|
println('$k')
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user