diff --git a/go/analysis/passes/stdversion/stdversion_test.go b/go/analysis/passes/stdversion/stdversion_test.go index 91865278ae9..d6a2e4556cd 100644 --- a/go/analysis/passes/stdversion/stdversion_test.go +++ b/go/analysis/passes/stdversion/stdversion_test.go @@ -23,5 +23,6 @@ func Test(t *testing.T) { analysistest.Run(t, dir, stdversion.Analyzer, "example.com/a", "example.com/sub", + "example.com/sub20", "example.com/old") } diff --git a/go/analysis/passes/stdversion/testdata/test.txtar b/go/analysis/passes/stdversion/testdata/test.txtar index 9e66cee8c63..0d27f112b04 100644 --- a/go/analysis/passes/stdversion/testdata/test.txtar +++ b/go/analysis/passes/stdversion/testdata/test.txtar @@ -13,6 +13,7 @@ go 1.21 use . use sub +use sub20 use old -- go.mod -- @@ -106,3 +107,42 @@ package old import "go/types" var _ types.Alias // no diagnostic: go.mod is too old for us to care + +-- sub/oldtagged.go -- +// The file Go version (1.16) overrides the go.mod Go version (1.21), +// even when this means a downgrade (#67123). +// (stdversion is silent for go.mod versions before 1.21: +// before the forward compatibility regime, the meaning +// of the go.mod version was not clearly defined.) + +//go:build go1.16 + +package sub + +import "bytes" +import "go/types" + +var _ = bytes.Clone // want `bytes.Clone requires go1.20 or later \(file is go1.16\)` +var _ = types.Alias // want `types.Alias requires go1.22 or later \(file is go1.16\)` + +-- sub20/go.mod -- +module example.com/sub20 + +go 1.20 + +-- sub20/oldtagged.go -- +// Same test again, but with a go1.20 mod, +// before the forward compatibility regime: +// The file's build tag effects selection, but +// not language semantics, so stdversion is silent. + +//go:build go1.16 + +package sub + +import "bytes" +import "go/types" + +var _ = bytes.Clone +var _ = types.Alias +