diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt index 65d90c36656..506edfcc677 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/enhancement/javaTypeUtils.kt @@ -186,10 +186,11 @@ private fun FirTypeParameter.getErasedUpperBound( return firstUpperBound.withArguments(firstUpperBound.typeArguments.map { ConeStarProjection }.toTypedArray()) } - val stopAt = potentiallyRecursiveTypeParameter ?: this + val alreadyVisited = mutableSetOf(potentiallyRecursiveTypeParameter, this) var current = (firstUpperBound as ConeTypeParameterType).lookupTag.typeParameterSymbol.fir - while (current != stopAt) { + while (current !in alreadyVisited) { + alreadyVisited += current val nextUpperBound = current.bounds.first().coneTypeUnsafe() if (nextUpperBound is ConeClassLikeType) {