From aff885bcd1f24e21fa7240a5d483d4bd116ba837 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Sat, 20 Nov 2021 16:23:34 +0300 Subject: [PATCH] [FIR] Prevent potential exponent complexity in isValidTypeParameterFromOuterDeclaration --- .../org/jetbrains/kotlin/fir/resolve/DeclarationUtils.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/DeclarationUtils.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/DeclarationUtils.kt index 19185eb6b1d..8f6043f25db 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/DeclarationUtils.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/DeclarationUtils.kt @@ -41,7 +41,13 @@ fun isValidTypeParameterFromOuterDeclaration( return true // Extra check is required because of classDeclaration will be resolved later } + val visited = mutableSetOf() + fun containsTypeParameter(currentDeclaration: FirDeclaration?): Boolean { + if (currentDeclaration == null || !visited.add(currentDeclaration)) { + return false + } + if (currentDeclaration is FirTypeParameterRefsOwner) { if (currentDeclaration.typeParameters.any { it.symbol == typeParameterSymbol }) { return true