cgen: fix nested map index check (fix #14683) (#14687)

yuyi 2022-06-06 11:29:22 +08:00 committed by Chewing_Bever
parent c2315b6c86
commit d28840036c
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 25 additions and 1 deletions

View File

@ -484,7 +484,7 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
if !node.is_option {
g.or_block(tmp_opt, node.or_expr, elem_type)
}
g.write('\n$cur_line*($elem_type_str*)${tmp_opt}.data')
g.write('\n${cur_line}(*($elem_type_str*)${tmp_opt}.data)')
}
}
}

View File

@ -0,0 +1,24 @@
struct Foo {
mut:
foo map[int]Bar
}
struct Bar {
mut:
bar map[int]string
}
fn test_nested_map_index() ? {
f := Foo{
foo: {
11: Bar{
bar: {
22: 'hello'
}
}
}
}
ret := f.foo[11]?.bar[22]?
println(ret)
assert ret == 'hello'
}