diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt index dcfac819a33..8c61d999cf7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt @@ -194,6 +194,10 @@ class DelegatedMemberGenerator( declaration.overriddenSymbols = basePropertySymbols[declaration]?.flatMap { fakeOverrideGenerator.getOverriddenSymbolsInSupertypes(it, superClasses) }?.filter { it.owner != declaration }.orEmpty() + declaration.getter!!.overriddenSymbols = declaration.overriddenSymbols.mapNotNull { it.owner.getter?.symbol } + if (declaration.isVar) { + declaration.setter!!.overriddenSymbols = declaration.overriddenSymbols.mapNotNull { it.owner.setter?.symbol } + } } else -> continue } @@ -301,18 +305,9 @@ class DelegatedMemberGenerator( annotationGenerator.generate(delegateProperty, firDelegateProperty) val getter = delegateProperty.getter!! - getter.overriddenSymbols = - firDelegateProperty.generateOverriddenAccessorSymbols( - firSubClass, - isGetter = true - ) annotationGenerator.generate(getter, firDelegateProperty) if (delegateProperty.isVar) { val setter = delegateProperty.setter!! - setter.overriddenSymbols = - firDelegateProperty.generateOverriddenAccessorSymbols( - firSubClass, isGetter = false - ) annotationGenerator.generate(setter, firDelegateProperty) } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt index 216efafe8d0..f46af86ee2b 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/FakeOverrideGenerator.kt @@ -391,13 +391,13 @@ class FakeOverrideGenerator( declarationStorage.classifierStorage.getIrClassSymbol(overriddenContainingClass.symbol).owner as? IrClass ?: return emptyList() - return if (overriddenContainingIrClass in superClasses) { - // `overridden` was a FIR declaration in some of the supertypes - listOf(irProducer(overridden)) - } else { - // There were no FIR declaration in supertypes, but we know that we have fake overrides in some of them - superClasses.mapNotNull { - declarationStorage.getFakeOverrideInClass(it, overridden.fir)?.let { fakeOverrideInClass -> + return superClasses.mapNotNull { superClass -> + if (superClass == overriddenContainingIrClass) { + // `overridden` was a FIR declaration in some of the supertypes + irProducer(overridden) + } else { + // There were no FIR declaration in supertypes, but we know that we have fake overrides in some of them + declarationStorage.getFakeOverrideInClass(superClass, overridden.fir)?.let { fakeOverrideInClass -> @Suppress("UNCHECKED_CAST") irProducer(fakeOverrideInClass.symbol as F) } diff --git a/compiler/testData/codegen/box/delegation/sealedClass.kt b/compiler/testData/codegen/box/delegation/sealedClass.kt index 52e831b38a4..cf996b820c4 100644 --- a/compiler/testData/codegen/box/delegation/sealedClass.kt +++ b/compiler/testData/codegen/box/delegation/sealedClass.kt @@ -1,5 +1,4 @@ // TARGET_BACKEND: JVM_IR -// IGNORE_BACKEND_FIR: JVM_IR // WITH_STDLIB sealed class A : CharSequence { diff --git a/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.ir.txt b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.ir.txt index 98999113419..060a2d17000 100644 --- a/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.ir.txt +++ b/compiler/testData/ir/irText/classes/dataClasses/delegationInSealed.fir.ir.txt @@ -16,6 +16,7 @@ FILE fqName: fileName:/delegationInSealed.kt INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public [data] superTypes:[.A; kotlin.CharSequence]' FUN DELEGATED_MEMBER name:get visibility:public modality:OPEN <> ($this:.A.B, index:kotlin.Int) returnType:kotlin.Char [operator] overridden: + public abstract fun get (index: kotlin.Int): kotlin.Char [fake_override,operator] declared in .A public abstract fun get (index: kotlin.Int): kotlin.Char [operator] declared in kotlin.CharSequence $this: VALUE_PARAMETER name: type:.A.B VALUE_PARAMETER name:index index:0 type:kotlin.Int @@ -27,6 +28,7 @@ FILE fqName: fileName:/delegationInSealed.kt index: GET_VAR 'index: kotlin.Int declared in .A.B.get' type=kotlin.Int origin=null FUN DELEGATED_MEMBER name:subSequence visibility:public modality:OPEN <> ($this:.A.B, startIndex:kotlin.Int, endIndex:kotlin.Int) returnType:kotlin.CharSequence overridden: + public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence [fake_override] declared in .A public abstract fun subSequence (startIndex: kotlin.Int, endIndex: kotlin.Int): kotlin.CharSequence declared in kotlin.CharSequence $this: VALUE_PARAMETER name: type:.A.B VALUE_PARAMETER name:startIndex index:0 type:kotlin.Int @@ -40,10 +42,12 @@ FILE fqName: fileName:/delegationInSealed.kt endIndex: GET_VAR 'endIndex: kotlin.Int declared in .A.B.subSequence' type=kotlin.Int origin=null PROPERTY DELEGATED_MEMBER name:length visibility:public modality:OPEN [val] overridden: + public abstract length: kotlin.Int [fake_override,val] public abstract length: kotlin.Int [val] FUN DELEGATED_MEMBER name: visibility:public modality:OPEN <> ($this:.A.B) returnType:kotlin.Int correspondingProperty: PROPERTY DELEGATED_MEMBER name:length visibility:public modality:OPEN [val] overridden: + public abstract fun (): kotlin.Int [fake_override] declared in .A public abstract fun (): kotlin.Int declared in kotlin.CharSequence $this: VALUE_PARAMETER name: type:.A.B BLOCK_BODY diff --git a/compiler/testData/ir/irText/firProblems/SignatureClash.fir.ir.txt b/compiler/testData/ir/irText/firProblems/SignatureClash.fir.ir.txt index 3af7283cf62..200b9bf916e 100644 --- a/compiler/testData/ir/irText/firProblems/SignatureClash.fir.ir.txt +++ b/compiler/testData/ir/irText/firProblems/SignatureClash.fir.ir.txt @@ -92,6 +92,7 @@ FILE fqName: fileName:/SignatureClash.kt INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:DataClass modality:FINAL visibility:public [data] superTypes:[.Derived; .Delegate]' FUN DELEGATED_MEMBER name:bar visibility:public modality:OPEN <> ($this:.DataClass) returnType:kotlin.Unit overridden: + public abstract fun bar (): kotlin.Unit [fake_override] declared in .Derived public abstract fun bar (): kotlin.Unit declared in .Delegate $this: VALUE_PARAMETER name: type:.DataClass BLOCK_BODY