Skip to content

Commit

Permalink
Only bind to types in the root package scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Scarr committed Feb 26, 2018
1 parent e4e249e commit ffe972a
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions codegen/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func findGoType(prog *loader.Program, pkgName string, typeName string) (types.Ob
}

for astNode, def := range pkg.Defs {
if astNode.Name != typeName || isMethod(def) {
if astNode.Name != typeName || def.Parent() == nil || def.Parent() != pkg.Pkg.Scope() {
continue
}

Expand All @@ -38,15 +38,6 @@ func findGoType(prog *loader.Program, pkgName string, typeName string) (types.Ob
return nil, fmt.Errorf("unable to find type %s\n", fullName)
}

func isMethod(t types.Object) bool {
f, isFunc := t.(*types.Func)
if !isFunc {
return false
}

return f.Type().(*types.Signature).Recv() != nil
}

func findMethod(typ *types.Named, name string) *types.Func {
for i := 0; i < typ.NumMethods(); i++ {
method := typ.Method(i)
Expand Down

0 comments on commit ffe972a

Please sign in to comment.