[FIR] Ignore visited super types during bypass in FirInconsistentTypeParameterHelpers

Get rid of potential exponential complexity
This commit is contained in:
Ivan Kochurkin
2021-10-27 18:20:28 +03:00
committed by teamcity
parent 6e57341a3d
commit c9ad2b3bf9
3 changed files with 13 additions and 3 deletions
@@ -58,6 +58,7 @@ private fun buildDeepSubstitutionMultimap(
): Map<FirTypeParameterSymbol, ClassSymbolAndProjections> {
val result = mutableMapOf<FirTypeParameterSymbol, ClassSymbolAndProjections>()
val substitution = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
val visitedSupertypes = mutableSetOf<ConeKotlinType>()
val session = context.session
val typeContext = session.typeContext
@@ -94,9 +95,12 @@ private fun buildDeepSubstitutionMultimap(
}
for (superTypeRef in classSymbol.resolvedSuperTypeRefs) {
val fullyExpandedType = superTypeRef.coneType.fullyExpandedType(session)
if (!visitedSupertypes.add(fullyExpandedType))
return
val superClassSymbol = fullyExpandedType.toRegularClassSymbol(session)
withSuppressedDiagnostics(superTypeRef, context) {
val fullyExpandedType = superTypeRef.coneType.fullyExpandedType(session)
val superClassSymbol = fullyExpandedType.toRegularClassSymbol(session)
if (!fullyExpandedType.isEnum && superClassSymbol != null) {
fillInDeepSubstitutor(fullyExpandedType.typeArguments, superClassSymbol)
}
@@ -0,0 +1,7 @@
interface A
interface B : A
interface ListA : List<A>
interface ListB : List<B>
interface Z<<!INCONSISTENT_TYPE_PARAMETER_BOUNDS!>T<!>> where T : ListA, T : ListB
@@ -1,4 +1,3 @@
// FIR_IDENTICAL
interface A
interface B : A