golang/go

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

Aberta

#79.153 aberto em 1 de mai. de 2026

 (2 comentários) (1 reação) (0 responsável)Go (19.008 forks)batch import
FixPending

Métricas do repositório

Stars
 (133.883 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

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.

Guia do colaborador