Skip to content

cmd/go: stdversion check should be on by default for go test #77729

@mvdan

Description

@mvdan
env GOTOOLCHAIN=go1.26.0
exec go version

exec go run .
exec go test
exec go vet

-- go.mod --
module test

go 1.25.0
-- main.go --
package main

import "bytes"

func main() { var _ = (*bytes.Buffer).Peek }
-- main_test.go --
package main_test

import "testing"

func TestDummy(t *testing.T) {}
> env GOTOOLCHAIN=go1.26.0
> exec go version
[stdout]
go version go1.26.0 linux/amd64
[stderr]
go: downloading go1.26.0 (linux/amd64)
> exec go run .
> exec go test
[stdout]
PASS
ok  	test	0.001s
> exec go vet
[stderr]
main.go:5:39: bytes.Peek requires go1.26 or later (file is go1.25)
[exit status 1]

It's a shame that go test doesn't surface this problem; even though go vet and gopls do surface it loudly, the sooner the user can correct this problem, the better. Otherwise they could later on find themselves in a situation where they have to rewrite code to stop using new APIs or language features.

I also wonder why this check wasn't added to go test once it was introduced; it seems like a simple (and presumably fast) check that should have zero false negatives. I imagine there are other similar checks that would be a good addition as well.

Split from #77653 (comment).

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions