@@ -372,28 +372,21 @@ func typenames(t types.Type) []*types.TypeName {
372372 var tns []* types.TypeName
373373
374374 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-
389375 visit = func (t types.Type ) {
376+ if hasName , ok := t .(interface { Obj () * types.TypeName }); ok {
377+ tns = append (tns , hasName .Obj ())
378+ }
390379 switch t := t .(type ) {
391380 case * types.Basic :
392381 tns = append (tns , types .Universe .Lookup (t .Name ()).(* types.TypeName ))
393382 case * types.Named :
394- namedOrAlias (t )
383+ for t := range t .TypeArgs ().Types () {
384+ visit (t )
385+ }
395386 case * types.Alias :
396- namedOrAlias (t )
387+ for t := range t .TypeArgs ().Types () {
388+ visit (t )
389+ }
397390 case * types.TypeParam :
398391 tns = append (tns , t .Obj ())
399392 case * types.Pointer :
@@ -408,9 +401,8 @@ func typenames(t types.Type) []*types.TypeName {
408401 visit (t .Key ())
409402 visit (t .Elem ())
410403 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 ())
414406 }
415407 case * types.Signature :
416408 // Ignore the receiver: although it may be present, it has no meaning
@@ -430,9 +422,8 @@ func typenames(t types.Type) []*types.TypeName {
430422 visit (t .ExplicitMethod (i ).Type ())
431423 }
432424 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 ())
436427 }
437428 case * types.Union :
438429 panic ("Union in type expression" )
0 commit comments