@@ -10,6 +10,7 @@ package gcimporter
10
10
import (
11
11
"bytes"
12
12
"fmt"
13
+ "go/build"
13
14
"go/constant"
14
15
"go/types"
15
16
"io/ioutil"
@@ -255,7 +256,7 @@ var importedObjectTests = []struct {
255
256
{"go/internal/gcimporter.FindPkg" , "func FindPkg(path string, srcDir string) (filename string, id string)" },
256
257
257
258
// 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 }" },
259
260
{"crypto.Decrypter" , "type Decrypter interface{Decrypt(rand io.Reader, msg []byte, opts DecrypterOpts) (plaintext []byte, err error); Public() PublicKey}" },
260
261
{"encoding.BinaryMarshaler" , "type BinaryMarshaler interface{MarshalBinary() (data []byte, err error)}" },
261
262
{"io.Reader" , "type Reader interface{Read(p []byte) (n int, err error)}" },
@@ -264,6 +265,18 @@ var importedObjectTests = []struct {
264
265
{"go/types.Type" , "type Type interface{String() string; Underlying() Type}" },
265
266
}
266
267
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
+
267
280
func TestImportedTypes (t * testing.T ) {
268
281
testenv .NeedsGo1Point (t , 11 )
269
282
// This package only handles gc export data.
@@ -275,6 +288,12 @@ func TestImportedTypes(t *testing.T) {
275
288
continue // error reported elsewhere
276
289
}
277
290
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
+
278
297
if got != test .want {
279
298
t .Errorf ("%s: got %q; want %q" , test .name , got , test .want )
280
299
}
0 commit comments