From f09db67c896d659d4cea2c7fbaf21ce09b5d491d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 18 Feb 2024 11:25:25 +0000 Subject: [PATCH] use types.Info.PkgNameOf It accomplishes the same Implicits/Defs logic we were doing here. --- main.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index a30914b..39b9969 100644 --- a/main.go +++ b/main.go @@ -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()) { @@ -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"