]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix panic in 'go run -C'
authorOleksandr Redko <oleksandr.red+github@gmail.com>
Fri, 6 Feb 2026 18:52:22 +0000 (20:52 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 12 Feb 2026 18:43:05 +0000 (10:43 -0800)
Fixes #77483

Change-Id: Ie772ce1619beadc1a6db87aaf28a8d9c31f7d1b8
Reviewed-on: https://go-review.googlesource.com/c/go/+/742860
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Alexander <jitsu@google.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Reviewed-by: Ian Alexander <jitsu@google.com>
Auto-Submit: Sean Liao <sean@liao.dev>

src/cmd/go/internal/toolchain/select.go
src/cmd/go/testdata/script/mod_run_flags_issue77483.txt [new file with mode: 0644]

index 0cb93f67e1321c804846566df93ca1a694c652e1..e7a9af793c5b9da65f1d6d8dcb338ec02a8e6a24 100644 (file)
@@ -658,6 +658,9 @@ func maybeSwitchForGoInstallVersion(loaderstate *modload.State, minVers string)
                }
 
                if bf, ok := f.Value.(interface{ IsBoolFlag() bool }); !ok || !bf.IsBoolFlag() {
+                       if len(args) == 0 {
+                               return
+                       }
                        // The next arg is the value for this flag. Skip it.
                        args = args[1:]
                        continue
diff --git a/src/cmd/go/testdata/script/mod_run_flags_issue77483.txt b/src/cmd/go/testdata/script/mod_run_flags_issue77483.txt
new file mode 100644 (file)
index 0000000..9a5d367
--- /dev/null
@@ -0,0 +1,4 @@
+# Regression test for https://go.dev/issue/77483: 'go run -C' should not panic.
+
+! go run -C
+stderr 'flag needs an argument: -C'