mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: fix array of reference sumtype appending (#14797)
This commit is contained in:
parent
924239026c
commit
cf1fc6f090
@ -1342,7 +1342,7 @@ pub fn (t &Table) is_sumtype_or_in_variant(parent Type, typ Type) bool {
|
||||
if typ == 0 {
|
||||
return false
|
||||
}
|
||||
if t.type_kind(typ) == .sum_type && parent.idx() == typ.idx()
|
||||
if t.sym(typ).kind == .sum_type && parent.idx() == typ.idx()
|
||||
&& parent.nr_muls() == typ.nr_muls() {
|
||||
return true
|
||||
}
|
||||
|
35
vlib/v/tests/array_of_reference_sumtype_append_test.v
Normal file
35
vlib/v/tests/array_of_reference_sumtype_append_test.v
Normal file
@ -0,0 +1,35 @@
|
||||
struct Element {
|
||||
AbstractNode
|
||||
name string
|
||||
attributes []&Attribute
|
||||
}
|
||||
|
||||
struct Attribute {
|
||||
AbstractNode
|
||||
name string
|
||||
value string
|
||||
}
|
||||
|
||||
pub type Node = Attribute | Element
|
||||
|
||||
struct AbstractNode {
|
||||
pub mut:
|
||||
child_nodes []&Node
|
||||
}
|
||||
|
||||
pub fn (mut n AbstractNode) append_child(child &Node) {
|
||||
n.child_nodes << child
|
||||
}
|
||||
|
||||
fn test_array_of_reference_sumtype_append() {
|
||||
mut parent := &Element{
|
||||
name: 'parent'
|
||||
}
|
||||
mut child := &Element{
|
||||
name: 'child'
|
||||
}
|
||||
parent.append_child(child)
|
||||
|
||||
dump(parent)
|
||||
assert parent.child_nodes[0].name == 'child'
|
||||
}
|
Loading…
Reference in New Issue
Block a user