1
0
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:
yuyi 2022-06-20 17:23:53 +08:00 committed by GitHub
parent 924239026c
commit cf1fc6f090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -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
}

View 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'
}