Skip to content

cmd/go: compile error for toolchain default in go.mod, removed by mod tidy #73127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Snawoot opened this issue Apr 1, 2025 · 5 comments
Open
Labels
BugReport Issues describing a possible bug in the Go implementation. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@Snawoot
Copy link

Snawoot commented Apr 1, 2025

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.

@ldemailly
Copy link

default btw is a weird name for something that would work like GOTOOLCHAIN=local so should be local instead (neither work)

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Apr 1, 2025
@seankhliao seankhliao changed the title 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 Apr 1, 2025
@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Apr 1, 2025
@ldemailly
Copy link

@seankhliao it's not a warning, it's an error, go run . fails/stops with

go: updates to go.mod needed; to update it:
	go mod tidy

@Snawoot Snawoot changed the title 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 Apr 1, 2025
@Snawoot
Copy link
Author

Snawoot commented 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
Copy link

$ go run . go: updates to go.mod needed; to update it: go mod tidy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation. GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants