diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 34f70f97bc9..6af2d970448 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -676,8 +676,10 @@ class Fir2IrDeclarationStorage( val setter = property.setter // TODO: this checks are very preliminary, FIR resolve should determine backing field presence itself if (property.isConst || (property.modality != Modality.ABSTRACT && (irParent !is IrClass || !irParent.isInterface))) { - if (initializer != null || getter is FirDefaultPropertyGetter || - property.isVar && setter is FirDefaultPropertySetter + if (initializer != null || + getter is FirDefaultPropertyGetter || + property.isVar && setter is FirDefaultPropertySetter || + property.backingFieldSymbol.isReferenced ) { backingField = createBackingField( property, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, descriptor, diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt index 316b18fbe0f..c20fc2e864a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/FirCallResolver.kt @@ -515,6 +515,7 @@ class FirCallResolver( val candidate = candidates.single() val coneSymbol = candidate.symbol if (coneSymbol is FirBackingFieldSymbol) { + coneSymbol.isReferenced = true return buildBackingFieldReference { this.source = source resolvedSymbol = coneSymbol diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt index 2d776e76ebf..c6af0af9aa1 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/symbols/impl/FirVariableSymbol.kt @@ -32,7 +32,10 @@ open class FirPropertySymbol( constructor(name: Name) : this(CallableId(name)) } -class FirBackingFieldSymbol(callableId: CallableId) : FirVariableSymbol(callableId) +class FirBackingFieldSymbol( + callableId: CallableId, + var isReferenced: Boolean = false +) : FirVariableSymbol(callableId) class FirDelegateFieldSymbol>(callableId: CallableId) : FirVariableSymbol(callableId) { val delegate: FirExpression diff --git a/compiler/testData/codegen/box/operatorConventions/augmentedAssignmentInInitializer.kt b/compiler/testData/codegen/box/operatorConventions/augmentedAssignmentInInitializer.kt index d891ace8d69..4592c96c7ae 100644 --- a/compiler/testData/codegen/box/operatorConventions/augmentedAssignmentInInitializer.kt +++ b/compiler/testData/codegen/box/operatorConventions/augmentedAssignmentInInitializer.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR abstract class A { val b = B("O") diff --git a/compiler/testData/codegen/box/secondaryConstructors/withoutPrimarySimple.kt b/compiler/testData/codegen/box/secondaryConstructors/withoutPrimarySimple.kt index 266ee075d36..35092448120 100644 --- a/compiler/testData/codegen/box/secondaryConstructors/withoutPrimarySimple.kt +++ b/compiler/testData/codegen/box/secondaryConstructors/withoutPrimarySimple.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class A { val value: String get() = field + "K"