From 1c56a71b14166268dfebae356dddf925eecf46b6 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 25 Apr 2023 11:34:43 +0200 Subject: [PATCH] FirClassSubstitutionScope: don't recreate constructor type parameters w/out need #KT-58008 Fixed --- .../low-level-api-fir/testdata/onAirResolve/classInClass.txt | 2 +- .../testData/resolveWithStdlib/hashTableWithForEach.fir.txt | 2 +- .../testData/resolveWithStdlib/intellij/UastPatterns.fir.txt | 2 +- .../kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt | 5 ++++- .../testData/codegen/box/fir/TypeParameterInNestedClass2.kt | 1 - 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/analysis/low-level-api-fir/testdata/onAirResolve/classInClass.txt b/analysis/low-level-api-fir/testdata/onAirResolve/classInClass.txt index efe03b8cbf7..60d67660408 100644 --- a/analysis/low-level-api-fir/testdata/onAirResolve/classInClass.txt +++ b/analysis/low-level-api-fir/testdata/onAirResolve/classInClass.txt @@ -4,7 +4,7 @@ public final inner [ResolvedTo(BODY_RESOLVE)] class ONAIR<[ResolvedTo(STATUS)] T } public final [ResolvedTo(BODY_RESOLVE)] fun x(): R|X.Y| { - ^x R|SubstitutionOverride|() + ^x R|/X.Y.Y|() } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashTableWithForEach.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashTableWithForEach.fir.txt index 0a42714d027..92676258782 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashTableWithForEach.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashTableWithForEach.fir.txt @@ -15,7 +15,7 @@ FILE: hashTableWithForEach.kt R|/DEBUG| -> { ^ Q|java/util/Collections|.R|java/util/Collections.unmodifiableSet|, kotlin/collections/MutableMap.MutableEntry?>|>(R|kotlin/collections/mutableSetOf||>().R|kotlin/apply|>|>( = apply@fun R|kotlin/collections/MutableSet>|.(): R|kotlin/Unit| { this@R|/SomeHashTable|.R|/SomeHashTable.forEach|( = forEach@fun (key: R|@EnhancedNullability K|, value: R|@EnhancedNullability V|): R|kotlin/Unit| { - this@R|special/anonymous|.R|SubstitutionOverride|(R|SubstitutionOverride|(R|/key|, R|/value|)) + this@R|special/anonymous|.R|SubstitutionOverride|(R|/SomeHashTable.Entry.Entry|(R|/key|, R|/value|)) } ) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.fir.txt index bd86097e334..d9d4ba43dbb 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.fir.txt @@ -15,7 +15,7 @@ FILE: UastPatterns.kt ^uExpression R|/expressionCapture|((Q|UExpression|).R|kotlin/jvm/java|) } public final fun expressionCapture(clazz: R|java/lang/Class|): R|UExpressionPattern.Capture| { - ^expressionCapture Q|UExpressionPattern|.R|SubstitutionOverride|(R|/clazz|) + ^expressionCapture Q|UExpressionPattern|.R|/UExpressionPattern.Capture.Capture|(R|/clazz|) } public open class UElementPattern|> : R|ObjectPattern| { public constructor|>(clazz: R|java/lang/Class|): R|UElementPattern| { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt index 313e25b8ab4..5a0541f07a9 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirClassSubstitutionScope.kt @@ -281,12 +281,15 @@ class FirClassSubstitutionScope( ) private fun createSubstitutedData(member: FirCallableDeclaration, symbolForOverride: FirBasedSymbol<*>): SubstitutedData { + val memberOwnerClassLookupTag = + if (member is FirConstructor) (member.returnTypeRef.coneType as ConeClassLikeType).lookupTag + else member.dispatchReceiverClassLookupTagOrNull() val (newTypeParameters, substitutor) = FirFakeOverrideGenerator.createNewTypeParametersAndSubstitutor( session, member as FirTypeParameterRefsOwner, symbolForOverride, substitutor, - forceTypeParametersRecreation = dispatchReceiverTypeForSubstitutedMembers.lookupTag != member.dispatchReceiverClassLookupTagOrNull() + forceTypeParametersRecreation = dispatchReceiverTypeForSubstitutedMembers.lookupTag != memberOwnerClassLookupTag ) val receiverType = member.receiverParameter?.typeRef?.coneType diff --git a/compiler/testData/codegen/box/fir/TypeParameterInNestedClass2.kt b/compiler/testData/codegen/box/fir/TypeParameterInNestedClass2.kt index d98afe30e17..7e10603e51d 100644 --- a/compiler/testData/codegen/box/fir/TypeParameterInNestedClass2.kt +++ b/compiler/testData/codegen/box/fir/TypeParameterInNestedClass2.kt @@ -1,7 +1,6 @@ // WITH_STDLIB // WITH_COROUTINES // TARGET_BACKEND: JVM_IR -// IGNORE_BACKEND_K2: JVM_IR // ISSUE: KT-58008 import kotlin.coroutines.*