-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: add (or make explicit) tests for ambiguous imports in module mode #28806
Comments
I don't see anything obviously wrong here. It was always part of the design to be able to import to different versions of the same package. A submodule is also just another package. /cc @myitcv for further comments. |
cc @bcmills too 😄 @jadekler - can you provide a bit more detail? Because I get an error as expected (the import is ambiguous):
Full repro
But if I then
In case it's useful, I use the very hacky |
Ahhh. Thank you @myitcv, in my repro I had incorrectly depended upon too late of a version. When I bump it back down to v0.0.1, I see the same failure. Thanks for the confirmation. Before I make changes to this issue, let me ask y'all this: this result seems to indicate that it is subtly unsafe to carve out a submodule after-the-fact if anyone depends on your package. Do you agree? In which case I'd like to suggest that the documentation makes this clear. cc @hyangah @bradfitz re: x/tools, x/oauth2 (maybe y'all have already discovered and discussed this) |
What do you mean by "unsafe", exactly? I think the situation we've reproduced here is unfortunate (and could perhaps be better flagged/resolved), but I don't think it's unsafe in so far as we end up with a bad build. Come and join the party over in #27858 (comment) (linking to @bcmills's thoughts on this specifically) for more discussion on this! |
Unsafe as in, users' programs may break in the "ambiguous import" manner seen above. That is, you probably need to do major bumping when you carve out a submodule, instead of just a minor bump. Subtle as in, this is hard to see as a library maintainer without setting up a fairly convoluted check. SG, will catch up on that discussion and see if I have anything of worth to contribute heh. :) |
Got it. Just one small nit, the program itself doesn't break, the build does. And the build only breaks in response to us doing something, i.e. |
Turns out you can do this in a really funny way. Per #27858 (comment), you can make the carved-out submodule require the first version of the parent module that does not contain its contents. Although, I don't think you can do this atomically, since the "carve out commit" must be tagged parent=vNEXT as well as child=vNEXT, and in that same commit you need to have the require statement for parent=vNEXT. |
You can do it atomically (by tagging the parent and child vNEXT in the same commit), but you can't test it before you push (because you can't currently resolve unpublished module versions). 😕 |
Ohhh right. I had incorrectly thought there wouldn't be a sha until you push. But, that's obviously wrong. |
I had thought we had a test that confirmed the |
In addition to this, I observed we can't compute the correct go.sum entries. It doesn't cause build failure but verification is skipped. |
@hyangah Maybe my git noob-ness, but: does the commit sha change when you push? In #28806 (comment) I had naively thought the local sha would be OK to manually use. edit: Whoops, ignore this. I just had the realization that |
That's true, although omitting a |
Change https://golang.org/cl/255046 mentions this issue: |
…semantic version Test this behavior incidentally in a test for ambiguous import errors. (I rediscovered the error when writing the new test.) For #32567 Updates #28806 Change-Id: I323f05145734e5cf99818b9f04d65075f7c0f787 Reviewed-on: https://go-review.googlesource.com/c/go/+/255046 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
foo
with:foo/go.mod
foo/somefile.go
containingconst Version = "foo=0.0.1"
foo/bar/
with afoo/bar/somefile.go
containingconst Version = "foo=0.0.1"
...
require foo v0.0.1
fmt.Println(foo.Version) // expect "foo=0.0.1"
fmt.Println(bar.Version) // expect "foo=0.0.1"
...
foo
, make afoo/bar
its own submodule:foo/bar/go.mod
foo/bar/somefile.go
to now haveconst Version = "bar=1.0.0"
...
require bar v1.0.0
dependency (keeping therequire foo v0.0.1
dependency!)require bar v1.0.0
and viarequire foo v0.0.1
, in whichfoo/bar
was still part of the modulefmt.Println(bar.Version)
results inbar=1.0.0
EDIT: actually, you get the following error (see @myitcv excellent repro below):
What did you expect to see?
I'm not sure. Maybe this is WAI? I vaguely expected to see an error. I suspect there are some hidden subtleties here that could end up breaking people. Maybe since bar has to always be backwards compatible, this is OK?
Anyways, feel free to close if this is unsurprising. I thought it was subtle and maybe worth looking at, but y'all let me know.
EDIT: Ignore this, since my original post was flawed. In fact you cannot do this, which seems to imply carving out submodules after-the-fact is unsupported.
What did you see instead?
Go modules seems to silently replace
foo/bar/
in therequire foo v0.0.1
with thebar v1.0.0
version.EDIT: Ignore this, since my original post was flawed. In fact you cannot do this, which seems to imply carving out submodules after-the-fact is unsupported.
The text was updated successfully, but these errors were encountered: