Skip to content

Commit d3358c1

Browse files
committed
go/internal/gcimporter: fix test for Go 1.18 any
In Go 1.18 context uses any, not interface{}. Fix the test in a way that should work for both older and newer versions. For golang/go#49884. Change-Id: Ib8690876c6a9364b98f9c7ba739b953a8d7565d4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/369955 Trust: Russ Cox <[email protected]> Run-TryBot: Russ Cox <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent feb39d0 commit d3358c1

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

go/internal/gcimporter/gcimporter_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package gcimporter
1010
import (
1111
"bytes"
1212
"fmt"
13+
"go/build"
1314
"go/constant"
1415
"go/types"
1516
"io/ioutil"
@@ -255,7 +256,7 @@ var importedObjectTests = []struct {
255256
{"go/internal/gcimporter.FindPkg", "func FindPkg(path string, srcDir string) (filename string, id string)"},
256257

257258
// interfaces
258-
{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key interface{}) interface{}}"},
259+
{"context.Context", "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key any) any}"},
259260
{"crypto.Decrypter", "type Decrypter interface{Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error); Public() PublicKey}"},
260261
{"encoding.BinaryMarshaler", "type BinaryMarshaler interface{MarshalBinary() (data []byte, err error)}"},
261262
{"io.Reader", "type Reader interface{Read(p []byte) (n int, err error)}"},
@@ -264,6 +265,18 @@ var importedObjectTests = []struct {
264265
{"go/types.Type", "type Type interface{String() string; Underlying() Type}"},
265266
}
266267

268+
// TODO(rsc): Delete this init func after x/tools no longer needs to test successfully with Go 1.17.
269+
func init() {
270+
if build.Default.ReleaseTags[len(build.Default.ReleaseTags)-1] <= "go1.17" {
271+
for i := range importedObjectTests {
272+
if importedObjectTests[i].name == "context.Context" {
273+
// Expand any to interface{}.
274+
importedObjectTests[i].want = "type Context interface{Deadline() (deadline time.Time, ok bool); Done() <-chan struct{}; Err() error; Value(key interface{}) interface{}}"
275+
}
276+
}
277+
}
278+
}
279+
267280
func TestImportedTypes(t *testing.T) {
268281
testenv.NeedsGo1Point(t, 11)
269282
// This package only handles gc export data.
@@ -275,6 +288,12 @@ func TestImportedTypes(t *testing.T) {
275288
continue // error reported elsewhere
276289
}
277290
got := types.ObjectString(obj, types.RelativeTo(obj.Pkg()))
291+
292+
// TODO(rsc): Delete this block once go.dev/cl/368254 lands.
293+
if got != test.want && test.want == strings.ReplaceAll(got, "interface{}", "any") {
294+
got = test.want
295+
}
296+
278297
if got != test.want {
279298
t.Errorf("%s: got %q; want %q", test.name, got, test.want)
280299
}

0 commit comments

Comments
 (0)