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 <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
feaab9440b
commit
6a3e9aa2ab
|
@ -200,10 +200,7 @@ func (p *pass) findMissingImport(pkg string, syms map[string]bool) *importInfo {
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if candidate.name != "" && candidate.name != pkg {
|
if candidate.name != pkg && pkgInfo.name != pkg {
|
||||||
continue
|
|
||||||
}
|
|
||||||
if pkgInfo.name != pkg {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +374,7 @@ func (p *pass) assumeSiblingImportsValid() {
|
||||||
if imp, ok := importsByName[left]; ok {
|
if imp, ok := importsByName[left]; ok {
|
||||||
if _, ok := stdlib[imp.importPath]; ok {
|
if _, ok := stdlib[imp.importPath]; ok {
|
||||||
// We have the stdlib in memory; no need to guess.
|
// We have the stdlib in memory; no need to guess.
|
||||||
continue
|
rights = stdlib[imp.importPath]
|
||||||
}
|
}
|
||||||
p.addCandidate(imp, &packageInfo{
|
p.addCandidate(imp, &packageInfo{
|
||||||
// no name; we already know it.
|
// no name; we already know it.
|
||||||
|
|
|
@ -1918,10 +1918,12 @@ func TestSiblingImports(t *testing.T) {
|
||||||
|
|
||||||
import "local/log"
|
import "local/log"
|
||||||
import "my/bytes"
|
import "my/bytes"
|
||||||
|
import renamed "fmt"
|
||||||
|
|
||||||
func LogSomething() {
|
func LogSomething() {
|
||||||
log.Print("Something")
|
log.Print("Something")
|
||||||
bytes.SomeFunc()
|
bytes.SomeFunc()
|
||||||
|
renamed.Println("Something")
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -1932,6 +1934,7 @@ var _ = bytes.Buffer{}
|
||||||
|
|
||||||
func LogSomethingElse() {
|
func LogSomethingElse() {
|
||||||
log.Print("Something else")
|
log.Print("Something else")
|
||||||
|
renamed.Println("Yet another")
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -1940,6 +1943,7 @@ func LogSomethingElse() {
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
renamed "fmt"
|
||||||
"local/log"
|
"local/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1947,6 +1951,7 @@ var _ = bytes.Buffer{}
|
||||||
|
|
||||||
func LogSomethingElse() {
|
func LogSomethingElse() {
|
||||||
log.Print("Something else")
|
log.Print("Something else")
|
||||||
|
renamed.Println("Yet another")
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue