Skip to content

Commit cf1fc6f

Browse files
authored
ast: fix array of reference sumtype appending (#14797)
1 parent 9242390 commit cf1fc6f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

vlib/v/ast/table.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ pub fn (t &Table) is_sumtype_or_in_variant(parent Type, typ Type) bool {
13421342
if typ == 0 {
13431343
return false
13441344
}
1345-
if t.type_kind(typ) == .sum_type && parent.idx() == typ.idx()
1345+
if t.sym(typ).kind == .sum_type && parent.idx() == typ.idx()
13461346
&& parent.nr_muls() == typ.nr_muls() {
13471347
return true
13481348
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
struct Element {
2+
AbstractNode
3+
name string
4+
attributes []&Attribute
5+
}
6+
7+
struct Attribute {
8+
AbstractNode
9+
name string
10+
value string
11+
}
12+
13+
pub type Node = Attribute | Element
14+
15+
struct AbstractNode {
16+
pub mut:
17+
child_nodes []&Node
18+
}
19+
20+
pub fn (mut n AbstractNode) append_child(child &Node) {
21+
n.child_nodes << child
22+
}
23+
24+
fn test_array_of_reference_sumtype_append() {
25+
mut parent := &Element{
26+
name: 'parent'
27+
}
28+
mut child := &Element{
29+
name: 'child'
30+
}
31+
parent.append_child(child)
32+
33+
dump(parent)
34+
assert parent.child_nodes[0].name == 'child'
35+
}

0 commit comments

Comments
 (0)