Skip to content

Commit 8666ef4

Browse files
authored
cgen: fix dependency order error between sumtype and fixed array type (fix #16003) (#16009)
1 parent 95f57e9 commit 8666ef4

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5297,6 +5297,43 @@ fn (mut g Gen) sort_structs(typesa []&ast.TypeSymbol) []&ast.TypeSymbol {
52975297
}
52985298
}
52995299
}
5300+
ast.SumType {
5301+
for variant in sym.info.variants {
5302+
vsym := g.table.sym(variant)
5303+
if vsym.info !is ast.Struct {
5304+
continue
5305+
}
5306+
fields := g.table.struct_fields(vsym)
5307+
for field in fields {
5308+
if field.typ.is_ptr() {
5309+
continue
5310+
}
5311+
fsym := g.table.sym(field.typ)
5312+
if fsym.info is ast.Alias {
5313+
xsym := g.table.sym(fsym.info.parent_type)
5314+
if xsym.info !is ast.ArrayFixed {
5315+
continue
5316+
}
5317+
xdep := xsym.name
5318+
// skip if not in types list or already in deps
5319+
if xdep !in type_names || xdep in field_deps {
5320+
continue
5321+
}
5322+
field_deps << xdep
5323+
continue
5324+
}
5325+
if fsym.info !is ast.ArrayFixed {
5326+
continue
5327+
}
5328+
dep := fsym.name
5329+
// skip if not in types list or already in deps
5330+
if dep !in type_names || dep in field_deps {
5331+
continue
5332+
}
5333+
field_deps << dep
5334+
}
5335+
}
5336+
}
53005337
// ast.Interface {}
53015338
else {}
53025339
}

vlib/v/gen/c/testdata/sumtype_struct_depend_order.out

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type OneOrTwo = One | Two
2+
3+
struct One {
4+
sig u32
5+
num u32
6+
items [16]Three
7+
}
8+
9+
struct Two {
10+
sig u32
11+
num u64
12+
items [16]Three
13+
}
14+
15+
struct Three {
16+
}
17+
18+
pub fn (obj OneOrTwo) get_sig() u32 {
19+
return obj.sig
20+
}

0 commit comments

Comments
 (0)