diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 402f271d73..11c2b17e14 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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 {} } diff --git a/vlib/v/gen/c/testdata/sumtype_struct_depend_order.out b/vlib/v/gen/c/testdata/sumtype_struct_depend_order.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vlib/v/gen/c/testdata/sumtype_struct_depend_order.vv b/vlib/v/gen/c/testdata/sumtype_struct_depend_order.vv new file mode 100644 index 0000000000..0dc2bb3c4f --- /dev/null +++ b/vlib/v/gen/c/testdata/sumtype_struct_depend_order.vv @@ -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 +}