-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: import comments not enforced in module mode? #26367
Comments
I think this is actually a bug in |
Oh yeah: it's an intentional breakage in Check out the commit message: rsc/quote@fe488b8#diff-43a03299a3c3fed3d8ce7b820f3aca81 |
Hmm, there may be another bug here, though: it's possible that in module mode we're not enforcing canonical import path comments. |
I'm hitting similar issues when trying to port my v2 packages with vanity imports and
You can see the full build log for 1.10.3 on Linux here: https://travis-ci.org/mvdan/sh/jobs/404138919 Building this outside of GOPATH on the latest tip works fine. I presume that 1.10 needs fixing, unless I'm missing something obvious. |
I regret reminding people in the vgo-tour that canonical import paths even existed. I used the import comment in the tour to show that if you are using them, then vgo could use that information to derive the correct 'module' line for an auto-initialized go.mod. Unfortunately, what lots of people took away instead was that using modules would mean using import comments. In fact, the opposite is true: import comments are basically obsoleted by modules. The reason for introducing import comments was to make sure that if there were two different paths to name a package (because of custom import domain redirects) that an author could make sure all users were using the preferred name. Before that feature, there was no clear statement of the import path elements above the repository root. With modules, we now have the clear statement we lacked before: the module statement in go.mod. Because of this, the module loading code ignores import comments entirely, and I expect that once we switch to modules we will probably deprecate them officially. So it's working as intended that import comments are not enforced in module mode. @mvdan, I would suggest just dropping the import comments from the v2 revs of your repo. |
That makes sense - thank you for the clarification. I think we should document this well, though. The reason I was trying to make import comments work was because they were there before, and no part of the Go modules documentation told me they were to be deprecated. So this will be a non-issue once the feature is clearly marked as deprecated :) |
golang/go#26367 (comment) That said, this does clean up the potential for the two different versions of the same code imported in the same file to diverge. Signed-off-by: Tyler Dixon <tylerd@uber.com>
Which is of course less than ideal when a user operates in module mode but |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No; working from tip.
What operating system and processor architecture are you using (
go env
)?What did you do?
(rsc/quote@5d9f230 is the HEAD of master at the time of writing)
What did you expect to see?
Successful
go get
What did you see instead?
/cc @rsc @bcmills
The text was updated successfully, but these errors were encountered: