Open
Description
Go version
go version go1.24.1 linux/amd64
Output of go env
in your module/workspace:
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build416208600=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/user/src/test/go.mod'
GOMODCACHE='/home/user/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib64/go/1.24'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/usr/lib64/go/1.24/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.1'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
I'm following go.mod specification which allows to disable automatic toolchain switching with toolchain default
directive.
I'm using following minimal example to reproduce the issue:
main.go
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
go.mod
module github.com/Snawoot/test
go 1.24.1
toolchain default
What did you see happen?
Attempt to build or run it produces requires go mod tidy
and ends up with following error:
$ go run .
go: updates to go.mod needed; to update it:
go mod tidy
But running go mod tidy
strips toolchain
directive and leaves me with following go.mod
module github.com/Snawoot/test
go 1.24.1
What did you expect to see?
I expect go build
and go run
to not have false positive about "dirty" go.mod and run it with original go.mod without any issue. Also I expect go mod tidy
to respect specification and preserve directives I've set.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ldemailly commentedon Apr 1, 2025
default
btw is a weird name for something that would work likeGOTOOLCHAIN=local
so should belocal
instead (neither work)gabyhelp commentedon Apr 1, 2025
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
[-]go rejects go.mod with `toolchain default` and `go mod tidy` removes `toolchain default` directive[/-][+]cmd/go: warning for toolchain default in go.mod, removed by mod tidy[/+]ldemailly commentedon Apr 1, 2025
@seankhliao it's not a warning, it's an error,
go run .
fails/stops with[-]cmd/go: warning for toolchain default in go.mod, removed by mod tidy[/-][+]cmd/go: compile error for toolchain default in go.mod, removed by mod tidy[/+]Snawoot commentedon Apr 1, 2025
@seankhliao Sorry, but updated title is outright wrong. It's not a warning, it's ultimately a failure to compile. Editing title.
03094299179 commentedon Apr 2, 2025
$ go run . go: updates to go.mod needed; to update it: go mod tidy
[-]cmd/go: compile error for toolchain default in go.mod, removed by mod tidy[/-][+]cmd/go: compile error for "toolchain default" in go.mod, removed by mod tidy[/+]