Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions meta/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand All @@ -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)
Expand Down