@@ -372,28 +372,21 @@ func typenames(t types.Type) []*types.TypeName {
372
372
var tns []* types.TypeName
373
373
374
374
var visit func (types.Type )
375
-
376
- // TODO(jba): when typesinternal.NamedOrAlias adds TypeArgs, replace this type literal with it.
377
- namedOrAlias := func (t interface {
378
- TypeArgs () * types.TypeList
379
- Obj () * types.TypeName
380
- }) {
381
- tns = append (tns , t .Obj ())
382
- args := t .TypeArgs ()
383
- // TODO(jba): replace with TypeList.Types when this file is at 1.24.
384
- for i := range args .Len () {
385
- visit (args .At (i ))
386
- }
387
- }
388
-
389
375
visit = func (t types.Type ) {
376
+ if hasName , ok := t .(interface { Obj () * types.TypeName }); ok {
377
+ tns = append (tns , hasName .Obj ())
378
+ }
390
379
switch t := t .(type ) {
391
380
case * types.Basic :
392
381
tns = append (tns , types .Universe .Lookup (t .Name ()).(* types.TypeName ))
393
382
case * types.Named :
394
- namedOrAlias (t )
383
+ for t := range t .TypeArgs ().Types () {
384
+ visit (t )
385
+ }
395
386
case * types.Alias :
396
- namedOrAlias (t )
387
+ for t := range t .TypeArgs ().Types () {
388
+ visit (t )
389
+ }
397
390
case * types.TypeParam :
398
391
tns = append (tns , t .Obj ())
399
392
case * types.Pointer :
@@ -408,9 +401,8 @@ func typenames(t types.Type) []*types.TypeName {
408
401
visit (t .Key ())
409
402
visit (t .Elem ())
410
403
case * types.Struct :
411
- // TODO(jba): replace with Struct.Fields when this file is at 1.24.
412
- for i := range t .NumFields () {
413
- visit (t .Field (i ).Type ())
404
+ for f := range t .Fields () {
405
+ visit (f .Type ())
414
406
}
415
407
case * types.Signature :
416
408
// Ignore the receiver: although it may be present, it has no meaning
@@ -430,9 +422,8 @@ func typenames(t types.Type) []*types.TypeName {
430
422
visit (t .ExplicitMethod (i ).Type ())
431
423
}
432
424
case * types.Tuple :
433
- // TODO(jba): replace with Tuple.Variables when this file is at 1.24.
434
- for i := range t .Len () {
435
- visit (t .At (i ).Type ())
425
+ for v := range t .Variables () {
426
+ visit (v .Type ())
436
427
}
437
428
case * types.Union :
438
429
panic ("Union in type expression" )
0 commit comments