-
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: using a module path without dot fails to build after toolchain selection [1.20 backport] #61873
Comments
@gopherbot, please backport to Go 1.21. This is a very confusing failure mode. |
Backport issue(s) opened: #61896 (for 1.21). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
I think this is actually a bug in |
If so, that should imply that if you install It should also not be present if you set |
Change https://go.dev/cl/518415 mentions this issue: |
Both statements are true based on a quick local run. I think it would be fine to close this issue as fixed in the Go1.22 or Go1.21 milestone, and make a new one for Go 1.20 backport. But since it's being repurposed to be a backport issue directly, I'll update the title and labels accordingly. |
We do not index std as a whole module ever. When working in the main Go repo, files in package change often, so we don't want to pay the cost of reindexing all of std when what we really need is just to reindex strings. Per-package indexing works better for that case. When using a released Go toolchain, we don't have to worry about the whole module changing, but if we switch to whole-module indexing at that point, we have the potential for bugs that only happen in released toolchains. Probably not worth the risk. For similar reasons, we don't index the current work module as a whole module (individual packages are changing), so we use the heuristic that we only do whole-module indexing in the module cache. The new toolchain modules live in the module cache, though, and our heuristic was causing whole-module indexing for them. As predicted, enabling whole-module indexing for std when it's completely untested does in fact lead to bugs (a very minor one). This CL turns off whole-module indexing for std even when it is in the module cache, to bring toolchain module behavior back in line with the other ways to run toolchains. Updates #57001. For #61873. Change-Id: I5012dc713f566846eb4b2848facc7f75bc956eb9 Reviewed-on: https://go-review.googlesource.com/c/go/+/504119 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> (cherry picked from commit a7b1793) Reviewed-on: https://go-review.googlesource.com/c/go/+/518415 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
Closed by merging 1a91bb9 to release-branch.go1.20. |
This is fixed as far as Go 1.20. @dmitshur, I think there is still one final release planned for Go 1.19 — do you think this is worth fixing on that branch, given that Go 1.19 would normally be past its support window? |
@bcmills I tested out the original repro steps with Go 1.19 as the "target toolchain" instead of 1.20, and it's hard for me to tell if it's affected by the same bug as described in this issue or a different one. It doesn't work either, but the error is different: $ cd $(mktemp -d)
$ go mod init example/m
go: creating new go.mod: module example/m
$ go get go@1.19
go: downgraded go 1.21.0 => 1.19
$ echo "package main; func main() {}" > main.go
$ GOTOOLCHAIN=go1.19.12 go run .
import "": import of unknown directory
$ echo $?
1 There's some connection to #61871, but that issue is about error text in invalid programs, while this issue was about valid programs not working. (But it's possible their root cause is the same.) It's hard for me to say without more information, so leaving the decision to you. In general I think it's better not to break cmd/go in Go 1.19.13 at this point, even if it means some UX inconvenience (i.e., needing to include a "." in the import path of short example or test programs when trying to use them via toolchain selection). On the other hand if you're very confident in the safety of the fix and the same CL will work despite the error being seemingly different, you do have that opportunity to include the fix. |
My inclination is that it's not worth the risk to mess with the final 1.19 release: as a workaround, folks can always install it in |
Due to a bug in Go 1.20 (see golang/go#61873), when importing a module without a dot in it, we get: ``` 18:13 ❱ GOTOOLCHAIN="go1.20+auto" go get akvorado: ambiguous import: found package akvorado in multiple modules: akvorado (/home/bernat/code/free/akvorado) (/home/bernat/src/gocode/pkg/mod/golang.org/toolchain@v0.0.1-go1.20.linux-amd64/src/akvorado) ``` This issue was fixed in Go 1.20.8 which was just released. By using `go1.20.8` as a toolchain for anything <= 1.20, we still cover the use case introduced in dependabot#7884, but we also avoid this bug. `go1.20.8` is a valid toolchain. For Go 1.20, only `go1.20` is a valid version for `go` directive in `go.mod`.
Due to a bug in Go 1.20 (see golang/go#61873), when importing a module without a dot in it, we get: ``` 18:13 ❱ GOTOOLCHAIN="go1.20+auto" go get akvorado: ambiguous import: found package akvorado in multiple modules: akvorado (/home/bernat/code/free/akvorado) (/home/bernat/src/gocode/pkg/mod/golang.org/toolchain@v0.0.1-go1.20.linux-amd64/src/akvorado) ``` This issue was fixed in Go 1.20.8 which was just released. By using `go1.20.8` as a toolchain for anything <= 1.20, we still cover the use case introduced in #7884, but we also avoid this bug. `go1.20.8` is a valid toolchain. For Go 1.20, only `go1.20` is a valid version for `go` directive in `go.mod`.
Similar to #61871, but:
It works fine without toolchain selection, or if a dot is used in first path element.
I noticed because I usually type something short (i.e., without a dot in first path element) when running a throwaway program locally. I know import paths without a dot are reserved for the standard library and shouldn't be used, but
example/...
andtest/...
are reserved for user progams per #37641.CC @bcmills, @matloob, @rsc.
The text was updated successfully, but these errors were encountered: