x/tools/cmd/goimports: incorrectly walks GOPATH nested within the current module #29549
Labels
FrozenDueToAge
modules
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes the issue is reproducible with the latest version of go (
go1.12beta1
)What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The following
testscript
reproduces the issue:What did you expect to see?
Output:
because
main.go
is missing an import to satisfy the qualified identifiercore.
.What did you see instead?
Note that in this test, our
GOPATH
happens to be nested within the main module;GOPATH=$WORK/gopath
andGOMOD=$WORK/go.mod
.goimports
seems to unconditionally walk all subdirectories of the main module, including the nestedGOPATH
(which includes thepkg/mod
subdirectory). This appears to be wrong; we should probably prune theGOPATH
subdirectory tree for this phase of the walk.Note the error triggered by this unconditional walking is not a
goimports
bug per se, but rather this issueA clear workaround for this rather obscure edge case is to either not nest your GOPATH or prefix the nested GOPATH directory name with a hiding character (
_
or.
).cc @heschik @bradfitz @ianthehat @myitcv
The text was updated successfully, but these errors were encountered: