New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/cmd/goimports: goimports does not handle multiple duplicate packages #28213
Comments
I've tried this on previous commits and results are the same. |
Change https://golang.org/cl/142257 mentions this issue: |
The code in question is also in gofmt. Does it have the same problem? |
@josharian I run gofmt on the file in question, the result was correct (no duplicates). It may be an issue that I use gofmt installed with go some time ago (around Sep 17). I'll be happy to provide more information here, but I'm not sure if I should update gofmt to a newer version. Do you know how to do it safely? Will It worked with goimports installed several weeks (months?) ago. I first noticed this issue in a CI server that does builds in clean environments: it installs go & goimports (download https://storage.googleapis.com/golang/go1.9.linux-amd64.tar.gz, I managed to reproduce this issue locally after updating goimports ( |
I've tried it again and this issue wasn't before. Sorry for confusion. |
Confirmed no longer an issue on |
I can't reproduce either. |
What version of Go are you using (
go version
)?go version go1.9 linux/amd64
Does this issue reproduce with the latest release?
No
What operating system and processor architecture are you using (
go env
)?What did you do?
Take this code example: https://play.golang.org/p/Cw_JLKi807F
run
goimports file.go
What did you expect to see?
What did you see instead?
Additional analysis
Essentially, this bug reproduces when you have at least 3 duplicated packages, the more duplicated packages (ie. package4 x 2, package5 x 2) the more spectacular the results. Running goimports multiple times (O(logn)) eventually fixes the file and removes all duplicates.
It seems this problem was introduced in the following commit: https://go.googlesource.com/tools/+/12a7c317e894c0a622b5ed27f0a102fcdd56d1ad%5E%21/#F0
The text was updated successfully, but these errors were encountered: