[FIR2IR] Don't add synthetic propertiy fake overrides to parent class

This fixes a KMP issue where IrActualizer would add duplicate
fake overrides because the parent class would have both the getter
and the synthetic property in its list of declarations.
Now, the synthetic property fake overrides are still generated and
cached in the Fir2IrDeclarationStorage, but not added to the class.

#KT-60854 Fixed
This commit is contained in:
Kirill Rakhman
2023-08-11 16:06:03 +02:00
committed by Space Team
parent f459a6f6b5
commit 6fba6a2e3c
8 changed files with 57 additions and 14 deletions
@@ -99,7 +99,10 @@ class FakeOverrideGenerator(
if (none { it is IrProperty }) {
FirSyntheticPropertiesScope.createIfSyntheticNamesProviderIsDefined(session, firClass.defaultType(), useSiteMemberScope)?.let {
generateFakeOverridesForName(
irClass, it, name, firClass, this,
irClass, it, name, firClass,
// We pass result = null so that the IR declaration is not added to the class' list of declarations
// but is still cached in the declaration storage.
result = null,
// This parameter is only needed for data-class methods that is irrelevant for lazy library classes
realDeclarationSymbols = emptySet()
)
@@ -120,7 +123,7 @@ class FakeOverrideGenerator(
useSiteOrStaticScope: FirScope,
name: Name,
firClass: FirClass,
result: MutableList<IrDeclaration>,
result: MutableList<IrDeclaration>?,
realDeclarationSymbols: Set<FirBasedSymbol<*>>
) {
val isLocal = firClass !is FirRegularClass || firClass.isLocal
@@ -239,7 +242,7 @@ class FakeOverrideGenerator(
createIrDeclaration: (firDeclaration: D, irParent: IrClass, thisReceiverOwner: IrClass?, origin: IrDeclarationOrigin, isLocal: Boolean) -> I,
createFakeOverrideSymbol: (firDeclaration: D, baseSymbol: S) -> S,
baseSymbols: MutableMap<I, List<S>>,
result: MutableList<in I>,
result: MutableList<in I>?,
containsErrorTypes: (I) -> Boolean,
realDeclarationSymbols: Set<FirBasedSymbol<*>>,
computeDirectOverridden: FirTypeScope.(S) -> List<S>,
@@ -295,7 +298,8 @@ class FakeOverrideGenerator(
return
}
baseSymbols[irDeclaration] = baseFirSymbolsForFakeOverride
result += irDeclaration
result?.add(irDeclaration)
}
private inline fun <D : FirCallableDeclaration, reified S : FirCallableSymbol<D>> createFirFakeOverride(
@@ -33429,6 +33429,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr
runTest("compiler/testData/codegen/box/multiplatform/kt59613.kt");
}
@Test
@TestMetadata("kt60854.kt")
public void testKt60854() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/kt60854.kt");
}
@Test
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
@@ -33429,6 +33429,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo
runTest("compiler/testData/codegen/box/multiplatform/kt59613.kt");
}
@Test
@TestMetadata("kt60854.kt")
public void testKt60854() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/kt60854.kt");
}
@Test
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
+20
View File
@@ -0,0 +1,20 @@
// LANGUAGE: +MultiPlatformProjects
// TARGET_BACKEND: JVM_IR
// IGNORE_BACKEND_K1: ANY
// ISSUE: KT-60854
// WITH_STDLIB
// FULL_JDK
// MODULE: common
// FILE: common.kt
expect open class CancellationException(message: String?) : IllegalStateException
class TimeoutCancellationException(message: String) : CancellationException(message)
// MODULE: platform()()(common)
// FILE: platform.kt
public actual typealias CancellationException = java.util.concurrent.CancellationException
fun box(): String = "OK"
@@ -15,16 +15,6 @@ CLASS IR_EXTERNAL_JAVA_DECLARATION_STUB CLASS name:AX modality:ABSTRACT visibili
overridden:
public abstract fun getA (): @[FlexibleNullability] <root>.X? declared in <root>.X
$this: VALUE_PARAMETER FAKE_OVERRIDE name:<this> type:<root>.AX
PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:a visibility:public modality:OPEN [val]
overridden:
public abstract a: <root>.A? [val]
FUN IR_EXTERNAL_JAVA_DECLARATION_STUB name:<get-a> visibility:public modality:OPEN <> ($this:<root>.AX) returnType:@[FlexibleNullability] <root>.AX?
annotations:
Override
correspondingProperty: PROPERTY IR_EXTERNAL_JAVA_DECLARATION_STUB name:a visibility:public modality:OPEN [val]
overridden:
public abstract fun <get-a> (): <root>.A? declared in <root>.A
$this: VALUE_PARAMETER IR_EXTERNAL_JAVA_DECLARATION_STUB name:<this> type:<root>.AX
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:<root>.AX, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
overridden:
public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in <root>.A
@@ -33429,6 +33429,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/multiplatform/kt59613.kt");
}
@Test
@TestMetadata("kt60854.kt")
public void testKt60854() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/kt60854.kt");
}
@Test
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
@@ -33429,6 +33429,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack
runTest("compiler/testData/codegen/box/multiplatform/kt59613.kt");
}
@Test
@TestMetadata("kt60854.kt")
public void testKt60854() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/kt60854.kt");
}
@Test
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
@@ -28466,6 +28466,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/multiplatform/kt59613.kt");
}
@TestMetadata("kt60854.kt")
public void testKt60854() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/kt60854.kt");
}
@TestMetadata("noArgActualConstructor.kt")
public void testNoArgActualConstructor() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/noArgActualConstructor.kt");