Skip to content

Commit 7cc63d4

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

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

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

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -551,22 +551,19 @@ 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)
568554

569-
types.foreach(collector.traverse)
555+
def collect(tp: Type): Unit = tp.foreachPart:
556+
case ref @ TypeParamRef(_: PolyType, _) =>
557+
usedMethodTypeParamNames += ref.paramName
558+
case tp: TypeRef =>
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+
case _ =>
565+
566+
types.foreach(collect)
570567
(usedMethodTypeParamNames.toSet, usedClassTypeParams.toSet)
571568
end collectUsedTypeParams
572569
}

0 commit comments

Comments
 (0)