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

cgen: fix dep cycle for struct Node { children [4]&Node } closes #15136

This commit is contained in:
Joe Conigliaro 2022-07-21 16:16:24 +10:00
parent 8593408179
commit 49228e1acd
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -5074,9 +5074,25 @@ fn (mut g Gen) sort_structs(typesa []&ast.TypeSymbol) []&ast.TypeSymbol {
mut field_deps := []string{}
match sym.info {
ast.ArrayFixed {
dep := g.table.final_sym(sym.info.elem_type).name
if dep in type_names {
field_deps << dep
mut skip := false
// allow: `struct Node{ children [4]&Node }`
// skip adding the struct as a dependency to the fixed array: [4]&Node -> Node
// the struct must depend on the fixed array for definition order: Node -> [4]&Node
// NOTE: Is there is a simpler way to do this?
elem_sym := g.table.final_sym(sym.info.elem_type)
if elem_sym.info is ast.Struct && sym.info.elem_type.is_ptr() {
for field in elem_sym.info.fields {
if sym.idx == field.typ.idx() {
skip = true
break
}
}
}
if !skip {
dep := g.table.final_sym(sym.info.elem_type).name
if dep in type_names {
field_deps << dep
}
}
}
ast.Struct {