Skip to content

cmd/go: "get -tool" should fail if toolchain is below 1.24 in go.mod #74739

@dolmen

Description

@dolmen

When a tool is registered in go.mod with go get -tool, ensure that the toolchain requirement is at least 1.24.0 (either via the go directive or via toolchain). If that isn't the case, suggest to the user to upgrade (go mod edit -go=1.24.0).

Rationale

go1.23 (and lower) can't parse go.mod with a tool directive, so they can't be used as toolchain.

Go version

go version go1.24.5 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''

What did you do?

$ cat go.mod
module github.com/dolmen-go/goeval

go 1.23.0

require (
	golang.org/x/mod v0.24.0
	golang.org/x/tools v0.31.0
)

require golang.org/x/sync v0.12.0 // indirect

tool github.com/dolmen-go/goeval

What did you see happen?

go1.23.11 fails to parse a go.mod that contains a tool directive without a toolchain directive:

$ go1.23.11 list
go: errors parsing go.mod:
go.mod:12: unknown directive: tool
$ go1.23.11 build
go: errors parsing go.mod:
go.mod:12: unknown directive: tool

https://github.com/dolmen-go/goeval/actions/runs/16493582443/job/46633886516#step:4:7

What did you expect to see?

Either:

  • go 1.23 to ignore the tool directive
  • or go 1.24+ go get -tool fails to add the tool and suggests to increase the minimum go version in go.mod (go mod edit -go=1.24.0)

Edit

This issue was initially about the go directive in go.mod, but is now corrected to be about toolchain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.

    Type

    No type

    Projects

    Status

    All-But-Submitted

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions