From 6a3e9aa2ab7749d72d1006ee484271b4a11f96c2 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Mon, 10 Dec 2018 17:33:17 -0500 Subject: [PATCH] imports: fix renamed sibling imports Fix some logic errors around renamed sibling imports. The one in findMissingImport was just a silly mistake, the one in addCandidate was because I hadn't thought about renamed imports. Change-Id: Iecd0b4e6151bff7b8cb6ad21065f017fb1245bfd Reviewed-on: https://go-review.googlesource.com/c/153440 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- imports/fix.go | 7 ++----- imports/fix_test.go | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/imports/fix.go b/imports/fix.go index 535cfdc5..d009cd50 100644 --- a/imports/fix.go +++ b/imports/fix.go @@ -200,10 +200,7 @@ func (p *pass) findMissingImport(pkg string, syms map[string]bool) *importInfo { if !ok { continue } - if candidate.name != "" && candidate.name != pkg { - continue - } - if pkgInfo.name != pkg { + if candidate.name != pkg && pkgInfo.name != pkg { continue } @@ -377,7 +374,7 @@ func (p *pass) assumeSiblingImportsValid() { if imp, ok := importsByName[left]; ok { if _, ok := stdlib[imp.importPath]; ok { // We have the stdlib in memory; no need to guess. - continue + rights = stdlib[imp.importPath] } p.addCandidate(imp, &packageInfo{ // no name; we already know it. diff --git a/imports/fix_test.go b/imports/fix_test.go index 73d92dcb..ec22c60b 100644 --- a/imports/fix_test.go +++ b/imports/fix_test.go @@ -1918,10 +1918,12 @@ func TestSiblingImports(t *testing.T) { import "local/log" import "my/bytes" +import renamed "fmt" func LogSomething() { log.Print("Something") bytes.SomeFunc() + renamed.Println("Something") } ` @@ -1932,6 +1934,7 @@ var _ = bytes.Buffer{} func LogSomethingElse() { log.Print("Something else") + renamed.Println("Yet another") } ` @@ -1940,6 +1943,7 @@ func LogSomethingElse() { import ( "bytes" + renamed "fmt" "local/log" ) @@ -1947,6 +1951,7 @@ var _ = bytes.Buffer{} func LogSomethingElse() { log.Print("Something else") + renamed.Println("Yet another") } `