Skip to content

x/tools/cmd/goimports: import incorrectly rewritten #43212

@pkitszel

Description

@pkitszel

What version of Go are you using (go version)?

$ go version
`go version go1.15.6 linux/amd64`

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/przemek/.cache/go-build"
GOENV="/home/przemek/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/przemek/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/przemek/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build097643344=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I just go-get'ed goimports to format my code as usual:
goimports -w -l *.go
Then one of imports was changed from "github.com/Komosa/persistent-cookiejar" to "net/http/cookiejar" and code no longer compiles.
Here is minimal example: https://play.golang.org/p/T6ix7FGFPCn

As a side note: I have both packages installed. While I was minimizing the example, sometimes my desired import was preserved (thus named cookiejar "github...."). But I was unable to see any rule for this behavior.

What did you expect to see?

I would expect no rewrite for already-working imports.

What did you see instead?

Import is changed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions