Workspace mode is specifically for working with modules;
it doesn't make sense in GOPATH mode.
This also fixes a panic in (*modload.MainModuleSet).GoVersion
when go.work is present in GOPATH mode.
For #58767.
Change-Id: Ic6924352afb486fecc18e009e6b517f078e81094
Reviewed-on: https://go-review.googlesource.com/c/go/+/471600
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
base.Fatalf("go: -modfile cannot be used with commands that ignore the current module")
}
modRoots = nil
- } else if inWorkspaceMode() {
- // We're in workspace mode.
+ } else if workFilePath != "" {
+ // We're in workspace mode, which implies module mode.
} else {
if modRoot := findModuleRoot(base.Cwd()); modRoot == "" {
if cfg.ModFile != "" {
if !initialized {
panic("inWorkspaceMode called before modload.Init called")
}
+ if !Enabled() {
+ return false
+ }
return workFilePath != ""
}
--- /dev/null
+# Regression test for https://go.dev/issue/58767:
+# with an empty go.work file in GOPATH mode, calls to load.defaultGODEBUG for a
+# package named "main" panicked in modload.MainModules.GoVersion.
+
+env GO111MODULE=off
+cd example
+go list example/m
+
+-- example/go.work --
+go 1.21
+-- example/m/main.go --
+package main
+func main() {}