Closed
Description
Any time a client of go/types needs to find the types.PkgName
(or just the name) defined by an import, they must write logic equivalent to this:
// PkgName returns the local package name defined by the specified import.
func (info *types.Info) PkgName(imp *ast.ImportSpec) (*types.PkgName, bool) {
var obj types.Object
if imp.Name != nil {
obj = info.Defs[imp.Name]
} else {
obj = info.Implicits[imp]
}
pkgname, ok := obj.(*types.PkgName)
return pkgname, ok
}
I propose that we add this method to types.Info
.