Skip to content

x/tools/gopls: go version in go.work is ignored #76728

@koct9i

Description

@koct9i

gopls version

today master
v0.0.0-20251205185314-ebdeef31ea22

go env

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/khlebnikov/.cache/go-build'
GOENV='/home/khlebnikov/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/khlebnikov/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/khlebnikov/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go-1.23'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go-1.23/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/khlebnikov/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2535580455=/tmp/go-build -gno-record-gcc-switches'

What did you do?

using gopls

with go work:
$ cat ../go.work
go 1.24.2

while go version in $PATH
$ go version
go version go1.23.1 linux/amd64

What did you see happen?

gopls does not use go version from go.work


Rason:

GO111MODULE=auto disables modules when go tool sees only go.work file.

$ go version
go version go1.23.1 linux/amd64
$ echo 'go 1.24' > go.work
$ go version
go version go1.24.0 linux/amd64
$ GO111MODULE=auto go version
go version go1.23.1 linux/amd64

For go.work source view go version choosing is run without support of go modules and thus version in go.work file is ignored.

When go in $PATH is too old this breaks gopls for repositories like this:
https://github.com/containers/container-libs/

Fix:
golang/tools#606
golang.org/cl/724262

What did you expect to see?

gopls should use go version from go.work

Editor and settings

No response

Logs

$ cat ../go.work
go 1.24.2

use (
./common
./image
./storage
)

$ gopls check pkg/lockfile/lockfile.go
2025/12/06 12:57:02 Error:2025/12/06 12:57:02 go/packages.Load #1: err: exit status 1: stderr: go: go.work requires go >= 1.24.2 (running go 1.23.1)

view_id="1"
snapshot=0
directory=/home/khlebnikov/src/containers/container-libs/storage
query=[/home/khlebnikov/src/containers/container-libs/common/... /home/khlebnikov/src/containers/container-libs/image/... /home/khlebnikov/src/containers/container-libs/storage/... builtin]
packages=0
duration=10.600103ms

2025/12/06 12:57:02 Error:2025/12/06 12:57:02 initial workspace load failed: packages.Load error: err: exit status 1: stderr: go: go.work requires go >= 1.24.2 (running go 1.23.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.gopls/metadataIssues related to metadata loading in gopls

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions