cgen: fix indexexpr with orexpr (fix #21591) (#21592)

This commit is contained in:
Felipe Pena 2024-05-29 14:20:54 -03:00 committed by GitHub
parent 6c9dd62d35
commit f7a0eeb65c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -324,7 +324,7 @@ fn (mut g Gen) index_of_array(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,14 @@
struct Element {
children []int
}
fn f() []Element {
return [Element{
children: [1, 2, 3]
}]
}
fn test_main() {
a := f()[0]!.children[0]!.str()
assert dump(a) == '1'
}