1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix dependency order error between sumtype and fixed array type (fix #16003) (#16009)

This commit is contained in:
shove 2022-10-09 17:16:50 +08:00 committed by GitHub
parent 95f57e9206
commit 8666ef43fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 0 deletions

View File

@ -5297,6 +5297,43 @@ fn (mut g Gen) sort_structs(typesa []&ast.TypeSymbol) []&ast.TypeSymbol {
}
}
}
ast.SumType {
for variant in sym.info.variants {
vsym := g.table.sym(variant)
if vsym.info !is ast.Struct {
continue
}
fields := g.table.struct_fields(vsym)
for field in fields {
if field.typ.is_ptr() {
continue
}
fsym := g.table.sym(field.typ)
if fsym.info is ast.Alias {
xsym := g.table.sym(fsym.info.parent_type)
if xsym.info !is ast.ArrayFixed {
continue
}
xdep := xsym.name
// skip if not in types list or already in deps
if xdep !in type_names || xdep in field_deps {
continue
}
field_deps << xdep
continue
}
if fsym.info !is ast.ArrayFixed {
continue
}
dep := fsym.name
// skip if not in types list or already in deps
if dep !in type_names || dep in field_deps {
continue
}
field_deps << dep
}
}
}
// ast.Interface {}
else {}
}

View File

View File

@ -0,0 +1,20 @@
type OneOrTwo = One | Two
struct One {
sig u32
num u32
items [16]Three
}
struct Two {
sig u32
num u64
items [16]Three
}
struct Three {
}
pub fn (obj OneOrTwo) get_sig() u32 {
return obj.sig
}