From df3e398ef488a0f47c9b90ea8bdd68db05f490ac Mon Sep 17 00:00:00 2001 From: Henning Rogge Date: Thu, 22 Feb 2024 12:45:30 +0100 Subject: [PATCH] Instead of switching over to module typedefs when appropriate, recursivelylook through both options. --- meta/compile.go | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/meta/compile.go b/meta/compile.go index f6dc996..9591ec9 100644 --- a/meta/compile.go +++ b/meta/compile.go @@ -374,22 +374,7 @@ func (c *compiler) findTypedef(y *Type, parent Definition, qualifiedIdent string var found *Typedef if searchHeirarcy { - p := parent - for p != nil { - if ptd, ok := p.(HasTypedefs); ok { - if found = ptd.Typedefs()[ident]; found != nil { - break - } - } - p = p.getOriginalParent() - if p != nil { - // issue #50 - submodules can reference types in parent and in any - // other submodule w/o prefix - if m, isModule := p.(*Module); isModule && m.belongsTo != nil { - p = m.Parent().(Definition) - } - } - } + found = searchTypedef(parent, ident) } else { found = module.Typedefs()[ident] } @@ -406,6 +391,30 @@ func (c *compiler) findTypedef(y *Type, parent Definition, qualifiedIdent string return found, nil } +func searchTypedef(p Definition, ident string) *Typedef { + if ptd, ok := p.(HasTypedefs); ok { + if found := ptd.Typedefs()[ident]; found != nil { + return found + } + } + p = p.getOriginalParent() + if p == nil { + return nil + } + + // issue #50 - submodules can reference types in parent and in any + // other submodule w/o prefix + if m, isModule := p.(*Module); isModule && m.belongsTo != nil { + found := searchTypedef(m.Parent().(Definition), ident) + if found != nil { + return found + } + } + + // continue searching the original parent + return searchTypedef(p, ident) +} + func (c *compiler) typedef(t *Typedef) error { if t.dtype == nil { return fmt.Errorf("%s - %s type required", SchemaPath(t), t.ident)