mirror of
https://github.com/vlang/v.git
synced 2025-09-08 23:07:19 -04:00
This commit is contained in:
parent
0c1a02f910
commit
d9afebc277
@ -5269,8 +5269,17 @@ fn (mut g Gen) ident(node ast.Ident) {
|
||||
is_option_unwrap := is_option && typ == node.obj.typ.clear_flag(.option)
|
||||
cast_sym := g.table.sym(g.unwrap_generic(typ))
|
||||
if obj_sym.kind == .interface && cast_sym.kind == .interface {
|
||||
ptr := '*'.repeat(node.obj.typ.nr_muls())
|
||||
g.write('I_${obj_sym.cname}_as_I_${cast_sym.cname}(${ptr}${node.name})')
|
||||
if cast_sym.cname != obj_sym.cname {
|
||||
ptr := '*'.repeat(node.obj.typ.nr_muls())
|
||||
g.write('I_${obj_sym.cname}_as_I_${cast_sym.cname}(${ptr}${node.name})')
|
||||
} else {
|
||||
ptr := if is_option {
|
||||
''
|
||||
} else {
|
||||
'*'.repeat(node.obj.typ.nr_muls())
|
||||
}
|
||||
g.write('${ptr}${node.name}')
|
||||
}
|
||||
} else {
|
||||
mut is_ptr := false
|
||||
if i == 0 {
|
||||
|
42
vlib/v/tests/options/option_mut_if_none_test.v
Normal file
42
vlib/v/tests/options/option_mut_if_none_test.v
Normal file
@ -0,0 +1,42 @@
|
||||
module main
|
||||
|
||||
@[heap]
|
||||
interface IGameObject {
|
||||
mut:
|
||||
name string
|
||||
parent ?&IGameObject
|
||||
next ?&IGameObject
|
||||
child ?&IGameObject
|
||||
last_child ?&IGameObject
|
||||
}
|
||||
|
||||
@[heap]
|
||||
struct GameObject implements IGameObject {
|
||||
mut:
|
||||
name string
|
||||
parent ?&IGameObject
|
||||
next ?&IGameObject
|
||||
child ?&IGameObject
|
||||
last_child ?&IGameObject
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut v1 := &GameObject{
|
||||
name: 'v1'
|
||||
}
|
||||
v1.next = &GameObject{
|
||||
name: 'v2'
|
||||
}
|
||||
|
||||
mut next := v1.next
|
||||
for {
|
||||
if mut next != none {
|
||||
eprintln(next.name)
|
||||
assert next.name == 'v2'
|
||||
next = next.next
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
assert next == none
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user