Appending reference to array of sumtype references generates a new memory address.
islonely opened this issue · comments
Adam Oates commented
V doctor:
OS: linux, "Manjaro Linux"
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
CC version: cc (GCC) 12.1.0
vexe mtime: 2022-06-22 13:56:16
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 223b96a.585b514
Git version: git version 2.36.1
Git vroot status: weekly.2022.24-60-g585b5145-dirty
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 eee03626
What did you do?
v -g -o vdbg cmd/v && vdbg test.v
struct Element {
mut:
name string
value string
children []&Node
attributes []&Attribute
}
struct Attribute {
mut:
name string
value string
}
type Node = Element | Attribute
fn main() {
mut parent := &Element{
name: 'parent element'
}
attr := &Attribute{'foo', 'bar'}
parent.children << attr
parent.attributes << attr
println(voidptr(attr))
println(voidptr(parent.children[0]))
println(voidptr(parent.attributes[0]))
}
What did you expect to see?
Memory address of parent.children[0]
should match that of attr
.
What did you see instead?
0x7f192e67bfc0
0x7f192e69afc0
0x7f192e67bfc0
yuyi commented
I think it is right. attr
will cast to Node
, so the address will be changed.
Adam Oates commented
I think you may be right.