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 a62ed9cc0b8..04b6e5f2c3e 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 @@ -144,6 +144,7 @@ class FakeOverrideGenerator( ) irProperty.parent = this result += irProperty.withProperty { + discardAccessorsAccordingToBaseVisibility(baseSymbol) setOverriddenSymbolsForAccessors(declarationStorage, originalProperty, firOverriddenSymbol = baseSymbol) } } else if (fakeOverrideMode != FakeOverrideMode.SUBSTITUTION && originalProperty.allowsToHaveFakeOverrideIn(klass)) { @@ -160,15 +161,7 @@ class FakeOverrideGenerator( fakeOverrideProperty, irParent = this, thisReceiverOwner = declarationStorage.findIrParent(originalProperty) as? IrClass, origin = origin - ).apply { - // Do not create fake overrides for accessors if not allowed to do so, e.g., private lateinit var. - if (baseSymbol.fir.getter?.allowsToHaveFakeOverride != true) { - getter = null - } - if (baseSymbol.fir.setter?.allowsToHaveFakeOverride != true) { - setter = null - } - } + ) if (irProperty.backingField?.type?.containsErrorType() == true || irProperty.getter?.returnType?.containsErrorType() == true ) { @@ -176,6 +169,7 @@ class FakeOverrideGenerator( } irProperty.parent = this result += irProperty.withProperty { + discardAccessorsAccordingToBaseVisibility(baseSymbol) setOverriddenSymbolsForAccessors(declarationStorage, fakeOverrideProperty, firOverriddenSymbol = baseSymbol) } } @@ -185,6 +179,17 @@ class FakeOverrideGenerator( return result } + private fun IrProperty.discardAccessorsAccordingToBaseVisibility(baseSymbol: FirPropertySymbol) { + // Do not create fake overrides for accessors if not allowed to do so, e.g., private lateinit var. + if (baseSymbol.fir.getter?.allowsToHaveFakeOverride != true) { + getter = null + } + // or private setter + if (baseSymbol.fir.setter?.allowsToHaveFakeOverride != true) { + setter = null + } + } + private fun IrProperty.setOverriddenSymbolsForAccessors( declarationStorage: Fir2IrDeclarationStorage, property: FirProperty, diff --git a/compiler/testData/codegen/box/syntheticAccessors/kt10047.kt b/compiler/testData/codegen/box/syntheticAccessors/kt10047.kt index c8127aad812..8317ac0f765 100644 --- a/compiler/testData/codegen/box/syntheticAccessors/kt10047.kt +++ b/compiler/testData/codegen/box/syntheticAccessors/kt10047.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // FILE: a.kt package test2