@@ -551,43 +551,22 @@ object GenericSignatures {
551551 private def collectUsedTypeParams (types : List [Type ], initialSymbol : Symbol )(using Context ): (Set [Name ], Set [Symbol ]) =
552552 val usedMethodTypeParamNames = collection.mutable.Set .empty[Name ]
553553 val usedClassTypeParams = collection.mutable.Set .empty[Symbol ]
554+ val collector = new TypeTraverser :
555+ def traverse (tp : Type ) = tp.dealias match
556+ case ref @ TypeParamRef (_ : PolyType , _) =>
557+ usedMethodTypeParamNames += ref.paramName
558+ case TypeRef (pre, _) =>
559+ val sym = tp.typeSymbol
560+ if isTypeParameterInMethSig(sym, initialSymbol) then
561+ usedMethodTypeParamNames += sym.name
562+ else if sym.isTypeParam && sym.isContainedIn(initialSymbol.topLevelClass) then
563+ usedClassTypeParams += sym
564+ else
565+ traverse(pre)
566+ case _ =>
567+ traverseChildren(tp)
554568
555- def collect (tp : Type ): Unit = tp.dealias match
556- case ref @ TypeParamRef (_ : PolyType , _) =>
557- usedMethodTypeParamNames += ref.paramName
558- case TypeRef (pre, _) =>
559- val sym = tp.typeSymbol
560- if isTypeParameterInMethSig(sym, initialSymbol) then
561- usedMethodTypeParamNames += sym.name
562- else if sym.isTypeParam && sym.isContainedIn(initialSymbol.topLevelClass) then
563- usedClassTypeParams += sym
564- else
565- collect(pre)
566- case AppliedType (tycon, args) =>
567- collect(tycon)
568- args.foreach(collect)
569- case AndType (tp1, tp2) =>
570- collect(tp1)
571- collect(tp2)
572- case OrType (tp1, tp2) =>
573- collect(tp1)
574- collect(tp2)
575- case RefinedType (parent, _, refinedInfo) =>
576- collect(parent)
577- collect(refinedInfo)
578- case TypeBounds (lo, hi) =>
579- collect(lo)
580- collect(hi)
581- case ExprType (res) =>
582- collect(res)
583- case AnnotatedType (tpe, _) =>
584- collect(tpe)
585- case defn.ArrayOf (elemtp) =>
586- collect(elemtp)
587- case _ =>
588- ()
589-
590- types.foreach(collect)
569+ types.foreach(collector.traverse)
591570 (usedMethodTypeParamNames.toSet, usedClassTypeParams.toSet)
592571 end collectUsedTypeParams
593572}
0 commit comments