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

master
yuyi 2022-06-06 11:29:22 +08:00 committed by GitHub
parent df80b33dc0
commit ce771876a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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'
}