Skip to content

Commit

Permalink
Merge pull request #550 from 99designs/fix-unstable-marshaler-func
Browse files Browse the repository at this point in the history
Fix unstable external marshaler funcs with same name as type
  • Loading branch information
vektah authored Feb 18, 2019
2 parents a119584 + 9ebe771 commit 647c62a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion codegen/config/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,26 @@ func (b *Binder) FindObject(pkgName string, typeName string) (types.Object, erro
return nil, errors.Errorf("required package was not loaded: %s", fullName)
}

// function based marshalers take precedence
for astNode, def := range pkg.TypesInfo.Defs {
// only look at defs in the top scope
if def == nil || def.Parent() == nil || def.Parent() != pkg.Types.Scope() {
continue
}

if astNode.Name == typeName || astNode.Name == "Marshal"+typeName {
if astNode.Name == "Marshal"+typeName {
return def, nil
}
}

// then look for types directly
for astNode, def := range pkg.TypesInfo.Defs {
// only look at defs in the top scope
if def == nil || def.Parent() == nil || def.Parent() != pkg.Types.Scope() {
continue
}

if astNode.Name == typeName {
return def, nil
}
}
Expand Down

0 comments on commit 647c62a

Please sign in to comment.