cgen: fix unwrapped option selector assigning (#20816)

This commit is contained in:
Felipe Pena 2024-02-13 20:23:35 -03:00 committed by GitHub
parent 45ee800a34
commit ec21663f58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -3670,7 +3670,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
if is_as_cast { if is_as_cast {
g.write('(') g.write('(')
} }
if node.or_block.kind != .absent && !g.is_assign_lhs && g.table.sym(node.typ).kind != .chan { if node.or_block.kind != .absent && g.table.sym(node.typ).kind != .chan {
is_ptr := sym.kind in [.interface_, .sum_type] is_ptr := sym.kind in [.interface_, .sum_type]
stmt_str := g.go_before_last_stmt().trim_space() stmt_str := g.go_before_last_stmt().trim_space()
styp := g.typ(g.unwrap_generic(node.typ)) styp := g.typ(g.unwrap_generic(node.typ))

View File

@ -0,0 +1,20 @@
struct Tree {
mut:
nr_elems int
parent ?&Tree
}
fn (mut t Tree) set_nr_elems(name string, value int) {
t.parent or { return }.nr_elems = value
}
fn test_main() {
parent := Tree{
nr_elems: 11
}
mut child := Tree{
parent: &parent
}
child.set_nr_elems('Buzz', 123)
assert child.parent or { return }.nr_elems == 123
}