Skip to content

Commit

Permalink
use types.Info.PkgNameOf
Browse files Browse the repository at this point in the history
It accomplishes the same Implicits/Defs logic we were doing here.
  • Loading branch information
mvdan authored and pagran committed Feb 18, 2024
1 parent f08edd0 commit f09db67
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1773,13 +1773,8 @@ func (tf *transformer) useAllImports(file *ast.File) {
continue
}

// Simple import has no ast.Ident and is stored in Implicits separately.
pkgObj := tf.info.Implicits[imp]
if pkgObj == nil {
pkgObj = tf.info.Defs[imp.Name] // renamed or dot import
}

pkgScope := pkgObj.(*types.PkgName).Imported().Scope()
pkgName := tf.info.PkgNameOf(imp)
pkgScope := pkgName.Imported().Scope()
var nameObj types.Object
for _, name := range pkgScope.Names() {
if obj := pkgScope.Lookup(name); obj.Exported() && isSafeForInstanceType(obj.Type()) {
Expand All @@ -1800,7 +1795,7 @@ func (tf *transformer) useAllImports(file *ast.File) {
switch {
case imp.Name == nil: // import "pkg/path"
nameExpr = &ast.SelectorExpr{
X: ast.NewIdent(pkgObj.Name()),
X: ast.NewIdent(pkgName.Name()),
Sel: nameIdent,
}
case imp.Name.Name != ".": // import path2 "pkg/path"
Expand Down

0 comments on commit f09db67

Please sign in to comment.