aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2024-05-02 19:00:58 -0400
committerAlan Donovan <adonovan@google.com>2024-05-03 23:18:50 +0000
commitc16c816ac486df69471674bcaf6f1a8f76f2bdcf (patch)
tree95e24c7ae1b355f51967f783bdc556977ffff181
parent629a7be6d0a4808cd8e7af805986652d81bb975f (diff)
downloadgolang-x-tools-upstream-master.tar.gz
go/analysis/passes/stdversion: test *.go < go.mod versionupstream-master
This CL adds two tests for when the file's Go version (set by a //go:build constraint) is lower than the module's Go version. With a go.mod version < go1.21, the start of the "extended forward compatibility" regime, stdversion is silent. But with go1.21+, the build constraint in the file overrides the Go module version, even when lower. Fixes golang/go#67123 Change-Id: Iba37ff2d2c6d0e42a5bd0fe80bbd8dc6b1a25ac9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/582936 Reviewed-by: Tim King <taking@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--go/analysis/passes/stdversion/stdversion_test.go1
-rw-r--r--go/analysis/passes/stdversion/testdata/test.txtar40
2 files changed, 41 insertions, 0 deletions
diff --git a/go/analysis/passes/stdversion/stdversion_test.go b/go/analysis/passes/stdversion/stdversion_test.go
index 91865278a..d6a2e4556 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 9e66cee8c..0d27f112b 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
+