diff --git a/vlib/v/gen/c/index.v b/vlib/v/gen/c/index.v index 41053ddcb116e8..86d303e7625dfb 100644 --- a/vlib/v/gen/c/index.v +++ b/vlib/v/gen/c/index.v @@ -436,9 +436,9 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) { zero := g.type_default(info.value_type) g.write('${zero} })))') } - } else if g.inside_map_postfix || g.inside_map_infix || g.inside_map_index - || g.inside_array_index - || (g.is_assign_lhs && !g.is_arraymap_set && get_and_set_types) { + } else if !gen_or && (g.inside_map_postfix || g.inside_map_infix + || g.inside_map_index || g.inside_array_index || (g.is_assign_lhs && !g.is_arraymap_set + && get_and_set_types)) { zero := g.type_default(info.value_type) if node.is_setter { g.write('(*(${val_type_str}*)map_get_and_set((map*)') diff --git a/vlib/v/tests/builtin_arrays/array_append_map_with_or_expr_test.v b/vlib/v/tests/builtin_arrays/array_append_map_with_or_expr_test.v new file mode 100644 index 00000000000000..0c7263a8d29d7a --- /dev/null +++ b/vlib/v/tests/builtin_arrays/array_append_map_with_or_expr_test.v @@ -0,0 +1,10 @@ +fn test_array_append_map_with_or_expr() { + foobar := { + 'foo': 'Foo' + 'bar': 'Bar' + } + mut arr := []string{} + arr << foobar['foo'] + arr << foobar['baz'] or { 'Unknown' } + assert arr == ['Foo', 'Unknown'] +}