golang/go

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

开放

#79,153 创建于 2026年5月1日

 (2 条评论) (1 个反应) (0 位负责人)Go (19,008 个派生)batch import
FixPending

仓库指标

星标
 (133,883 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南