Skip to content

cmd/go: go mod tidy can automatically maintain toolchain directive when godebug default requires a higher toolchain #79153

@dmitshur

Description

@dmitshur

This is a minor friction report and a suggested feature request to address it, similar to #74739, except it's about the godebug directive and its default key.

Consider a module with a go 1.25.0 directive. If a godebug default directive is added with something higher than go1.25.0, then that becomes the minimum toolchain when working inside the module. It'd be good if the go command noticed that and automatically maintained the toolchain directive. As is, it leaves the module in a state where if an older go toolchain is used, it fails to parse the go.mod file:

$ GOTOOLCHAIN=local go version
go version go1.25.0 darwin/arm64
$ cd $(mktemp -d)
$ go mod init test
$ go get go@1.25.0
$ go mod edit -godebug default=go1.26.0
$ go mod tidy
$ go list -m
go: error loading go.mod:
go.mod:5: default=go1.26.0 too new (toolchain is go1.25.0)

If go mod tidy were to add a toolchain go1.26.0, then go list -m could succeed via the usual https://go.dev/doc/toolchain mechanism:

$ go list -m
go: downloading go1.26.0 (darwin/arm64)
test

The workaround for now is to manually maintain the toolchain directive (as was done in CL 772660 for example).

CC @golang/command-line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.FixPendingIssues that have a fix which has not yet been reviewed or submitted.GoCommandcmd/goToolProposalIssues describing a requested change to a Go tool or command-line program.help wanted

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions