-
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: tip breaks program flags in "go run" #64738
Comments
@bcmills This appears to be enough to fix the issue, but I'm not sure if it is the correct fix: diff --git a/src/cmd/go/internal/toolchain/select.go b/src/cmd/go/internal/toolchain/select.go
index 84fa7f685c..835d8117cc 100644
--- a/src/cmd/go/internal/toolchain/select.go
+++ b/src/cmd/go/internal/toolchain/select.go
@@ -15,6 +15,7 @@ import (
"os"
"path/filepath"
"runtime"
+ "slices"
"strconv"
"strings"
@@ -556,7 +557,15 @@ func goInstallVersion() bool {
// Make a best effort to parse flags so that module flags like -modcacherw
// will take effect (see https://go.dev/issue/64282).
- args := os.Args[2:]
+
+ // All flags past pkg@version should apply to pkg and not to the go
+ // command itself.
+ pkgIdx := slices.Index(os.Args, arg)
+ if pkgIdx == -1 {
+ return false
+ }
+
+ args := os.Args[2:pkgIdx]
for len(args) > 0 {
var err error
_, args, err = cmdflag.ParseOne(cmdFlags, args) |
Thanks for the report! This is a surprising gap in our test coverage. 😅 |
Change https://go.dev/cl/550237 mentions this issue: |
Change https://go.dev/cl/551215 mentions this issue: |
Change https://go.dev/cl/551255 mentions this issue: |
The straight revert in CL 551215 fixed this issue. Add a test case to make sure we don't reintroduce it. Test case copied from CL 550237 (by bcmills). Fixes #64738. Change-Id: I9654a1fd46fe1a1cc63ee6645a552ec21d720ad0 Reviewed-on: https://go-review.googlesource.com/c/go/+/551255 Reviewed-by: Michael Matloob <[email protected]> Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
…n' and 'go install' flags" This caused other problems, and for the purposes of the Go 1.22 release, we can just roll back to the Go 1.21 behavior and then decide in January what the correct path forward is. Revert of CL 546635. Unfixes golang#64282. Fixes golang#64738. For golang#57001. This reverts commit e44b8b1. Change-Id: I78753c76dcd0bc6dbc90caa17f73248c42e5f64a Reviewed-on: https://go-review.googlesource.com/c/go/+/551215 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
The straight revert in CL 551215 fixed this issue. Add a test case to make sure we don't reintroduce it. Test case copied from CL 550237 (by bcmills). Fixes golang#64738. Change-Id: I9654a1fd46fe1a1cc63ee6645a552ec21d720ad0 Reviewed-on: https://go-review.googlesource.com/c/go/+/551255 Reviewed-by: Michael Matloob <[email protected]> Auto-Submit: Russ Cox <[email protected]> Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
Go version
go version devel go1.22-d73b4322ed Thu Dec 14 22:24:40 2023 +0000 linux/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
Same behavior between Go tip and 1.21; the flag should be passed to the
cue
program without any error from cmd/go.What did you see instead?
It seems like cmd/go tries to parse the
-p json
flag, perhaps not realizing thatgo run
takes an arbitrary number of flags and arguments to pass on to the main package being run:In my case,
import -p json
go after the single package argument, so cmd/go should not attempt to parse them.cc @bcmills I suspect this might be a very recent regression due to https://go-review.googlesource.com/c/go/+/546635. I haven't bisected, but I've also never run into this error before.
The text was updated successfully, but these errors were encountered: