Skip to content

Commit

Permalink
cgen: fix indexexpr with orexpr (fix #21591) (#21592)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed May 29, 2024
1 parent 6c9dd62 commit f7a0eeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/gen/c/index.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)')
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions vlib/v/tests/indexexpr_or_test.v
Original file line number Diff line number Diff line change
@@ -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'
}

0 comments on commit f7a0eeb

Please sign in to comment.