cgen: fix error of for_in map_literal (#9310)
parent
3951c351c6
commit
e235022e10
|
@ -31,6 +31,12 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||||
p.inside_match = true // reuse the same var for perf instead of inside_sql TODO rename
|
p.inside_match = true // reuse the same var for perf instead of inside_sql TODO rename
|
||||||
node = p.sql_expr()
|
node = p.sql_expr()
|
||||||
p.inside_match = false
|
p.inside_match = false
|
||||||
|
} else if p.tok.lit == 'map' && p.peek_tok.kind == .lcbr && !(p.builtin_mod
|
||||||
|
&& p.file_base == 'map.v') {
|
||||||
|
p.next() // `map`
|
||||||
|
p.next() // `{`
|
||||||
|
node = p.map_init()
|
||||||
|
p.check(.rcbr) // `}`
|
||||||
} else {
|
} else {
|
||||||
if p.inside_if && p.is_generic_name() {
|
if p.inside_if && p.is_generic_name() {
|
||||||
// $if T is string {}
|
// $if T is string {}
|
||||||
|
|
|
@ -75,6 +75,18 @@ fn test_for_in_map_of_fixed_array() {
|
||||||
assert rets[2] == 'cc, [5, 6]'
|
assert rets[2] == 'cc, [5, 6]'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_for_in_map_of_fixed_array_literal() {
|
||||||
|
mut rets := []string{}
|
||||||
|
|
||||||
|
for k, v in map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!} {
|
||||||
|
println('$k, $v')
|
||||||
|
rets << '$k, $v'
|
||||||
|
}
|
||||||
|
assert rets[0] == 'aa, [1, 2]'
|
||||||
|
assert rets[1] == 'bb, [3, 4]'
|
||||||
|
assert rets[2] == 'cc, [5, 6]'
|
||||||
|
}
|
||||||
|
|
||||||
fn test_for_mut_in_map_of_fixed_array() {
|
fn test_for_mut_in_map_of_fixed_array() {
|
||||||
mut rets := []string{}
|
mut rets := []string{}
|
||||||
mut m := map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!}
|
mut m := map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!}
|
||||||
|
|
Loading…
Reference in New Issue