cmd/go/internal/modload: update WillBeEnabled to check for go.work

In the case where GO111MODULE=auto, we checked whether there was a
go.mod file to see if modules would be enabled, but did not check for a
go.work file. This brought WillBeEnabled out of sync with Init, which
does check for a go.work file. And that resulted with toolchain
selection not taking workspaces into account with GO111MODULE=auto.

For #76728

Change-Id: I9dd232b2e645b97524ffdf544bcd7e3d6a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/753700
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
This commit is contained in:
Michael Matloob
2026-03-10 12:41:41 -04:00
committed by Michael Matloob
parent dfd2e8027c
commit 7337b4669b
2 changed files with 14 additions and 1 deletions

View File

@@ -608,7 +608,7 @@ func (loaderstate *State) WillBeEnabled() bool {
return false
}
return FindGoMod(base.Cwd()) != ""
return FindGoMod(base.Cwd()) != "" || loaderstate.FindGoWork(base.Cwd()) != ""
}
// FindGoMod returns the name of the go.mod file for this command,

View File

@@ -0,0 +1,13 @@
# #76728: with GO111MODULE=auto, we didn't switch toolchains properly
# in a workspace.
env GO111MODULE=auto
env TESTGO_VERSION=go1.23.0
env TESTGO_VERSION_SWITCH=switch
go version
! stdout 1\.23\.0
stdout 1\.24\.0
-- go.work --
go 1.24.0