Skip to content

Commit af75817

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
cmd/go: disable workspace mode in GOPATH mode
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 <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 89c3f7c commit af75817

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/cmd/go/internal/modload/init.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ func Init() {
388388
base.Fatalf("go: -modfile cannot be used with commands that ignore the current module")
389389
}
390390
modRoots = nil
391-
} else if inWorkspaceMode() {
392-
// We're in workspace mode.
391+
} else if workFilePath != "" {
392+
// We're in workspace mode, which implies module mode.
393393
} else {
394394
if modRoot := findModuleRoot(base.Cwd()); modRoot == "" {
395395
if cfg.ModFile != "" {
@@ -496,6 +496,9 @@ func inWorkspaceMode() bool {
496496
if !initialized {
497497
panic("inWorkspaceMode called before modload.Init called")
498498
}
499+
if !Enabled() {
500+
return false
501+
}
499502
return workFilePath != ""
500503
}
501504

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Regression test for https://go.dev/issue/58767:
2+
# with an empty go.work file in GOPATH mode, calls to load.defaultGODEBUG for a
3+
# package named "main" panicked in modload.MainModules.GoVersion.
4+
5+
env GO111MODULE=off
6+
cd example
7+
go list example/m
8+
9+
-- example/go.work --
10+
go 1.21
11+
-- example/m/main.go --
12+
package main
13+
func main() {}

0 commit comments

Comments
 (0)