diff --git a/vlib/v/gen/c/index.v b/vlib/v/gen/c/index.v index 4bda72b2b2..c691e59383 100644 --- a/vlib/v/gen/c/index.v +++ b/vlib/v/gen/c/index.v @@ -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)') } } } diff --git a/vlib/v/tests/indexexpr_or_test.v b/vlib/v/tests/indexexpr_or_test.v new file mode 100644 index 0000000000..d2dcd1370e --- /dev/null +++ b/vlib/v/tests/indexexpr_or_test.v @@ -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' +}