Skip to content

Commit 08c2019

Browse files
authored
cgen: fix array append map value with or expr (fix #22674) (#22678)
1 parent 7bd2bef commit 08c2019

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

vlib/v/gen/c/index.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
436436
zero := g.type_default(info.value_type)
437437
g.write('${zero} })))')
438438
}
439-
} else if g.inside_map_postfix || g.inside_map_infix || g.inside_map_index
440-
|| g.inside_array_index
441-
|| (g.is_assign_lhs && !g.is_arraymap_set && get_and_set_types) {
439+
} else if !gen_or && (g.inside_map_postfix || g.inside_map_infix
440+
|| g.inside_map_index || g.inside_array_index || (g.is_assign_lhs && !g.is_arraymap_set
441+
&& get_and_set_types)) {
442442
zero := g.type_default(info.value_type)
443443
if node.is_setter {
444444
g.write('(*(${val_type_str}*)map_get_and_set((map*)')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn test_array_append_map_with_or_expr() {
2+
foobar := {
3+
'foo': 'Foo'
4+
'bar': 'Bar'
5+
}
6+
mut arr := []string{}
7+
arr << foobar['foo']
8+
arr << foobar['baz'] or { 'Unknown' }
9+
assert arr == ['Foo', 'Unknown']
10+
}

0 commit comments

Comments
 (0)