aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorMichael Matloob <matloob@golang.org>2026-03-25 14:05:36 -0400
committerGopher Robot <gobot@golang.org>2026-03-26 10:41:32 -0700
commit7c1806932fb91c7f8f8d17be7c1a63aa3d6cf175 (patch)
tree9e10e4131a03c79b6b4c60147735efd4d9a901d6 /src/cmd
parent1cfd0dc9a3416c1077acfcd44ad0084dd508116a (diff)
downloadgo-7c1806932fb91c7f8f8d17be7c1a63aa3d6cf175.tar.xz
cmd/go: default to Go 1.20 GODEBUGs in GOPATH mode
We used MainModules.GoVersion to get the Go version to use for godebugs in GOPATH mode. That returned Go 1.16 which is the default version for modules to use when they don't have a go directive, but is modules specific and doesn't make sense for GOPATH mode. Set the version to 1.20. For #73973 Change-Id: Iaa5bb77498d5860f2372ffda8a6b88a26a6a6964 Reviewed-on: https://go-review.googlesource.com/c/go/+/759240 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: t hepudds <thepudds1460@gmail.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/go/alldocs.go10
-rw-r--r--src/cmd/go/internal/help/helpdoc.go10
-rw-r--r--src/cmd/go/internal/load/godebug.go31
-rw-r--r--src/cmd/go/testdata/script/godebug_default_gopath.txt9
4 files changed, 39 insertions, 21 deletions
diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go
index 52aa6c7fb4..4be78b33bb 100644
--- a/src/cmd/go/alldocs.go
+++ b/src/cmd/go/alldocs.go
@@ -2878,11 +2878,11 @@
// GOPATH mode import path checking (see 'go help importpath').
//
// In GOPATH mode, the default GODEBUG values built into a binary
-// will be those used in Go 1.20, setting the same GODEBUG values
-// as when a module specifies "godebug default=go1.20". To use
-// different GODEBUG settings, the GODEBUG environment variable must
-// be set to override those values. This also means that the standard
-// library tests will not run properly with GO111MODULE=off.
+// will be the same GODEBUG values as when a module specifies
+// "godebug default=go1.20". To use different GODEBUG settings, the
+// GODEBUG environment variable must be set to override those values.
+// This also means that the standard library tests will not run
+// properly with GO111MODULE=off.
//
// See https://go.dev/s/go15vendor for details.
//
diff --git a/src/cmd/go/internal/help/helpdoc.go b/src/cmd/go/internal/help/helpdoc.go
index 5f77b88536..4b1444ee3b 100644
--- a/src/cmd/go/internal/help/helpdoc.go
+++ b/src/cmd/go/internal/help/helpdoc.go
@@ -525,11 +525,11 @@ Code in GOPATH mode vendor directories is not subject to
GOPATH mode import path checking (see 'go help importpath').
In GOPATH mode, the default GODEBUG values built into a binary
-will be those used in Go 1.20, setting the same GODEBUG values
-as when a module specifies "godebug default=go1.20". To use
-different GODEBUG settings, the GODEBUG environment variable must
-be set to override those values. This also means that the standard
-library tests will not run properly with GO111MODULE=off.
+will be the same GODEBUG values as when a module specifies
+"godebug default=go1.20". To use different GODEBUG settings, the
+GODEBUG environment variable must be set to override those values.
+This also means that the standard library tests will not run
+properly with GO111MODULE=off.
See https://go.dev/s/go15vendor for details.
diff --git a/src/cmd/go/internal/load/godebug.go b/src/cmd/go/internal/load/godebug.go
index 7bb873fa7d..a6bcdad627 100644
--- a/src/cmd/go/internal/load/godebug.go
+++ b/src/cmd/go/internal/load/godebug.go
@@ -42,6 +42,24 @@ func ParseGoDebug(text string) (key, value string, err error) {
return k, v, nil
}
+func defaultGODEBUGGoVersion(loaderstate *modload.State, p *Package) string {
+ if !loaderstate.Enabled() {
+ // GOPATH mode. Use Go 1.20.
+ return "1.20"
+ }
+ if loaderstate.RootMode == modload.NoRoot && p.Module != nil {
+ // This is go install pkg@version or go run pkg@version.
+ // Use the Go version from the package.
+ // If there isn't one, then assume Go 1.20, the last
+ // version before GODEBUGs were introduced (#56986).
+ if goVersion := p.Module.GoVersion; goVersion != "" {
+ return goVersion
+ }
+ return "1.20"
+ }
+ return loaderstate.MainModules.GoVersion(loaderstate)
+}
+
// defaultGODEBUG returns the default GODEBUG setting for the main package p.
// When building a test binary, directives, testDirectives, and xtestDirectives
// list additional directives from the package under test.
@@ -49,17 +67,8 @@ func defaultGODEBUG(loaderstate *modload.State, p *Package, directives, testDire
if p.Name != "main" {
return ""
}
- goVersion := loaderstate.MainModules.GoVersion(loaderstate)
- if loaderstate.RootMode == modload.NoRoot && p.Module != nil {
- // This is go install pkg@version or go run pkg@version.
- // Use the Go version from the package.
- // If there isn't one, then assume Go 1.20,
- // the last version before GODEBUGs were introduced.
- goVersion = p.Module.GoVersion
- if goVersion == "" {
- goVersion = "1.20"
- }
- }
+
+ goVersion := defaultGODEBUGGoVersion(loaderstate, p)
var m map[string]string
diff --git a/src/cmd/go/testdata/script/godebug_default_gopath.txt b/src/cmd/go/testdata/script/godebug_default_gopath.txt
new file mode 100644
index 0000000000..2bdf8369ae
--- /dev/null
+++ b/src/cmd/go/testdata/script/godebug_default_gopath.txt
@@ -0,0 +1,9 @@
+env GO111MODULE=off
+
+go list -f '{{.DefaultGODEBUG}}'
+! stdout netedns0
+
+-- foo.go --
+package main
+
+func main() {} \ No newline at end of file