Skip to content

x/tools/cmd/goimports: fails to distinguish package from global variable #7463

Closed
@gopherbot

Description

@gopherbot

by peterbourgon:

$ go version
go version go1.2.1 darwin/amd64

$ cat a.go
package main

import (
        logpkg "log"
        "os"
)

var (
        log = logpkg.New(os.Stdout, "", 0)
)

func main() {
        b()
}

$ cat b.go
~/src/tmp/logerr cat b.go
package main

func b() {
        log.Printf("hello")
}

$ goimports -d b.go
goimports -d b.go
diff b.go gofmt/b.go
--- /var/folders/lj/1qllh78d2qqbyxkdg5jldcym0000gn/T/gofmt154060612     2014-03-04
14:56:26.000000000 +0100
+++ /var/folders/lj/1qllh78d2qqbyxkdg5jldcym0000gn/T/gofmt436718547     2014-03-04
14:56:26.000000000 +0100
@@ -1,5 +1,7 @@
 package main

+import "log"
+
 func b() {
        log.Printf("hello")
 }

goimports doesn't detect that log.Printf in b.go refers to the global variable
"log" defined in a.go, and erroneously imports the log package. Put another
way, the expected diff is nothing.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions