mirror of
https://github.com/vlang/v.git
synced 2025-09-16 19:06:24 -04:00
cgen: fix unwrapped option selector assigning (#20816)
This commit is contained in:
parent
45ee800a34
commit
ec21663f58
@ -3670,7 +3670,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
|
||||
if is_as_cast {
|
||||
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]
|
||||
stmt_str := g.go_before_last_stmt().trim_space()
|
||||
styp := g.typ(g.unwrap_generic(node.typ))
|
||||
|
20
vlib/v/tests/option_selector_assign_test.v
Normal file
20
vlib/v/tests/option_selector_assign_test.v
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user