mirror of
https://github.com/vlang/v.git
synced 2025-09-15 10:27:19 -04:00
parent
1f8f6d0e7d
commit
11acee1a5b
@ -4065,11 +4065,12 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
|
||||
g.write('*')
|
||||
}
|
||||
g.write('${tmp_var} = ')
|
||||
if is_ptr {
|
||||
mut needs_addr := false
|
||||
needs_deref := is_ptr && !is_option_unwrap
|
||||
if needs_deref {
|
||||
g.write('*(')
|
||||
}
|
||||
needs_addr := is_option_unwrap && node.expr !in [ast.Ident, ast.PrefixExpr]
|
||||
if is_option_unwrap {
|
||||
} else if is_option_unwrap && !is_ptr {
|
||||
needs_addr = node.expr !in [ast.Ident, ast.PrefixExpr]
|
||||
if !needs_addr {
|
||||
g.write('&')
|
||||
} else {
|
||||
@ -4098,7 +4099,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
|
||||
g.write('.')
|
||||
}
|
||||
g.write(field_name)
|
||||
if is_ptr {
|
||||
if needs_deref {
|
||||
g.write(')')
|
||||
}
|
||||
if needs_addr {
|
||||
|
48
vlib/v/tests/options/option_nested_selector_test.v
Normal file
48
vlib/v/tests/options/option_nested_selector_test.v
Normal file
@ -0,0 +1,48 @@
|
||||
module main
|
||||
|
||||
@[heap]
|
||||
interface IGameObject {
|
||||
mut:
|
||||
name string
|
||||
parent ?&IGameObject
|
||||
next ?&IGameObject
|
||||
child ?&IGameObject
|
||||
last_child ?&IGameObject
|
||||
add_child(mut o IGameObject)
|
||||
}
|
||||
|
||||
@[heap]
|
||||
struct GameObject implements IGameObject {
|
||||
mut:
|
||||
name string
|
||||
parent ?&IGameObject
|
||||
next ?&IGameObject
|
||||
child ?&IGameObject
|
||||
last_child ?&IGameObject
|
||||
}
|
||||
|
||||
fn (mut gameobject GameObject) add_child(mut o IGameObject) {
|
||||
o.parent = gameobject
|
||||
if gameobject.last_child != none {
|
||||
gameobject.last_child.next = o
|
||||
} else {
|
||||
gameobject.child = o
|
||||
}
|
||||
gameobject.last_child = o
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut v1 := &GameObject{
|
||||
name: 'v1'
|
||||
}
|
||||
mut v2 := &GameObject{
|
||||
name: 'v2'
|
||||
}
|
||||
mut v3 := &GameObject{
|
||||
name: 'v3'
|
||||
}
|
||||
v1.add_child(mut v2)
|
||||
v1.add_child(mut v3)
|
||||
|
||||
assert v1.child?.next?.name == 'v3'
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user