Skip to content

Commit 27f5e3e

Browse files
tanishikinglrytz
andauthored
Use Type.foreachPart collectUsedTypeParams
Co-authored-by: Lukas Rytz <lukas.rytz@gmail.com>
1 parent 9b85e44 commit 27f5e3e

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -551,22 +551,18 @@ 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)
554+
def collector(tp: Type): Unit = tp.foreachPart:
555+
case ref@TypeParamRef(_: PolyType, _) =>
556+
usedMethodTypeParamNames += ref.paramName
557+
case TypeRef(pre, _) =>
558+
val sym = tp.typeSymbol
559+
if isTypeParameterInMethSig(sym, initialSymbol) then
560+
usedMethodTypeParamNames += sym.name
561+
else if sym.isTypeParam && sym.isContainedIn(initialSymbol.topLevelClass) then
562+
usedClassTypeParams += sym
563+
case _ =>
568564

569-
types.foreach(collector.traverse)
565+
types.foreach(collector)
570566
(usedMethodTypeParamNames.toSet, usedClassTypeParams.toSet)
571567
end collectUsedTypeParams
572568
}

0 commit comments

Comments
 (0)