Skip to content

Commit ec21663

Browse files
authored
cgen: fix unwrapped option selector assigning (#20816)
1 parent 45ee800 commit ec21663

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3670,7 +3670,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
36703670
if is_as_cast {
36713671
g.write('(')
36723672
}
3673-
if node.or_block.kind != .absent && !g.is_assign_lhs && g.table.sym(node.typ).kind != .chan {
3673+
if node.or_block.kind != .absent && g.table.sym(node.typ).kind != .chan {
36743674
is_ptr := sym.kind in [.interface_, .sum_type]
36753675
stmt_str := g.go_before_last_stmt().trim_space()
36763676
styp := g.typ(g.unwrap_generic(node.typ))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
struct Tree {
2+
mut:
3+
nr_elems int
4+
parent ?&Tree
5+
}
6+
7+
fn (mut t Tree) set_nr_elems(name string, value int) {
8+
t.parent or { return }.nr_elems = value
9+
}
10+
11+
fn test_main() {
12+
parent := Tree{
13+
nr_elems: 11
14+
}
15+
mut child := Tree{
16+
parent: &parent
17+
}
18+
child.set_nr_elems('Buzz', 123)
19+
assert child.parent or { return }.nr_elems == 123
20+
}

0 commit comments

Comments
 (0)