Skip to content
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

cmd/go: ambiguous import path not detected when the colliding path is in the standard library #35270

Open
gertcuykens opened this issue Oct 31, 2019 · 4 comments
Assignees
Milestone

Comments

@gertcuykens
Copy link
Contributor

@gertcuykens gertcuykens commented Oct 31, 2019

Suggest in Go 1.14 we go one step further when GO111MODULE="on", outside and inside! GOPATH, module path must be specified to prevent shenanigans.

When trying to create a module crypto outside gopath you get

% go mod init
go: cannot determine module path for source directory /Users/gert/crypto (outside GOPATH, module path must be specified)

Perfect, but if you do that inside gopath

(force GO111MODULE="on")
% mkdir $GOPATH/src/crypto
% cd $GOPATH/src/crypto
% echo "package crypto" > c_test.go
% go mod init
% cat go.mod
module crypto
go 1.14
% go test -v
=== RUN   TestRC4OutOfBoundsWrite
--- PASS: TestRC4OutOfBoundsWrite (0.00s)
=== RUN   TestCTROutOfBoundsWrite
--- PASS: TestCTROutOfBoundsWrite (0.00s)
=== RUN   TestOFBOutOfBoundsWrite
--- PASS: TestOFBOutOfBoundsWrite (0.00s)
=== RUN   TestCFBEncryptOutOfBoundsWrite
--- PASS: TestCFBEncryptOutOfBoundsWrite (0.00s)
=== RUN   TestCFBDecryptOutOfBoundsWrite
--- PASS: TestCFBDecryptOutOfBoundsWrite (0.00s)
PASS
ok      crypto  0.049s

Not only is it allowed, you even launch the wrong test files from GOROOT

I understand this is done for backward compatible sake, but GOPATH must die and end up somewhere as a dot folder hidden only used for cach.

Furthermore I suggest to change error message

go: cannot determine module path for source directory /Users/gert/crypto (outside GOPATH, module path must be specified)

to

go: cannot determine module path for source directory /Users/gert/crypto (module path must be specified)

to stop promoting people to use GOPATH

(related to: #35070)

@bcmills
Copy link
Member

@bcmills bcmills commented Nov 5, 2019

This has ~nothing to do with specifying module paths: it would be conceptually ok (if somewhat fragile) to create a module crypto provided that it does not define any packages that are also defined in GOPATH/src.

The problem here is that the existing ambiguous import error is not detecting the collision between the user's module and the standard library. That should be a much easier (and less invasive) fix.

CC @jayconrod

Loading

@bcmills bcmills changed the title cmd/go: when GO111MODULE="on" outside and inside! GOPATH, module path must be specified to prevent shenanigans cmd/go: ambiguous import path not detected when the colliding path is in the standard library Nov 5, 2019
@bcmills bcmills added this to the Backlog milestone Nov 5, 2019
@bcmills
Copy link
Member

@bcmills bcmills commented May 3, 2021

See also #26227.

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Nov 10, 2021

@bcmills Is this likely to happen for 1.18? Thanks.

Loading

@bcmills bcmills removed this from the Go1.18 milestone Nov 10, 2021
@bcmills bcmills added this to the Go1.19 milestone Nov 10, 2021
@bcmills
Copy link
Member

@bcmills bcmills commented Nov 10, 2021

I'm not sure. It should be a fairly easy fix, but it doesn't need to hold up the release; moving to 1.19 for now, but I may move it back if the fix turns out to be small enough to go in during the freeze.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants