Skip to content

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

Open
@Snawoot

Description

@Snawoot

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.

Activity

ldemailly

ldemailly commented on Apr 1, 2025

@ldemailly

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

added
BugReportIssues describing a possible bug in the Go implementation.
on Apr 1, 2025
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[/+] on Apr 1, 2025
added
NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
on Apr 1, 2025
ldemailly

ldemailly commented on Apr 1, 2025

@ldemailly

@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
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[/+] on Apr 1, 2025
Snawoot

Snawoot commented on Apr 1, 2025

@Snawoot
ContributorAuthor

@seankhliao Sorry, but updated title is outright wrong. It's not a warning, it's ultimately a failure to compile. Editing title.

03094299179

03094299179 commented on Apr 2, 2025

@03094299179

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

changed the title [-]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[/+] on May 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Snawoot@ldemailly@seankhliao@gabyhelp@03094299179

        Issue actions

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