Skip to content

x/tools/cmd/goimports: goimports removes used import, breaks build #28645

@dcelasun

Description

@dcelasun

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

$ go version
go version go1.11.1 linux/amd64

goimports from 34b416b.

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
GOARCH="amd64"
GOBIN="/home/dcelasun/go/bin"
GOCACHE="/home/dcelasun/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dcelasun/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
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-build196516147=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ git clone https://github.com/dcelasun/importbug.git $GOPATH/src/github.com/dcelasun/importbug
$ cd $GOPATH/src/github.com/dcelasun/importbug
$ go get -u golang.org/x/tools/cmd/goimports
$ goimports -l -w main.go
$ go build

See: https://github.com/dcelasun/importbug

What did you expect to see?

Successfully build the program.

What did you see instead?

$ go build
# github.com/dcelasun/importbug
./main.go:8:14: undefined: fb

because goimports removed the github.com/dcelasun/importbug/go-foobar import.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions