internal/typesinternal: suppress jsonv2 warning The GOEXPERIMENT=jsonv2 added in Go1.25 allows imports of encoding/json/v2 and encoding/json/jsontext. If the go version is at least 1.25, we should suppress "too new" warnings for symbols in these packages to avoid a false positive (since we don't know the specific build tags when determining the too new symbols). Fixes golang/go#80691 Change-Id: Id4f35e00c561f49d367da9e122c2bbc960c7f440 Reviewed-on: https://go-review.googlesource.com/c/tools/+/812840 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alex Putman <aputman@golang.org>
diff --git a/gopls/internal/test/marker/testdata/diagnostics/stdversion_jsonv2.txt b/gopls/internal/test/marker/testdata/diagnostics/stdversion_jsonv2.txt new file mode 100644 index 0000000..0e74a98 --- /dev/null +++ b/gopls/internal/test/marker/testdata/diagnostics/stdversion_jsonv2.txt
@@ -0,0 +1,24 @@ +This test verifies that "too new" diagnostics from the stdversion analyzer +are suppressed for jsonv2 when the go version is go1.25 or later. +See golang/go#80691 + +-- env -- +GOEXPERIMENT=jsonv2 +-- flags -- +-min_go_command=go1.25 +-max_go_command=go1.26 + +-- go.mod -- +module example.com + +go 1.25 + +-- a/a.go -- +//go:build goexperiment.jsonv2 || go1.27 +package a + +import "encoding/json/v2" + +func _() { + _ = json.Marshal // no diagnostic, see golang/go#80691 +}
diff --git a/internal/typesinternal/toonew.go b/internal/typesinternal/toonew.go index 9cc58fd..386c59c 100644 --- a/internal/typesinternal/toonew.go +++ b/internal/typesinternal/toonew.go
@@ -25,6 +25,10 @@ // requires go1.24 && goexperiment.synctest || go1.25 return disallowed } + if (pkg.Path() == "encoding/json/v2" || pkg.Path() == "encoding/json/jsontext") && versions.AtLeast(version, "go1.25") { + // requires go1.25 && goexperiment.jsonv2 || go1.27 + return disallowed + } // Pass 1: package-level symbols. symbols := stdlib.PackageSymbols[pkg.Path()]