diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 572328dd856..e518733fadc 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -362,6 +362,30 @@ class CallAndReferenceGenerator( return null } + private fun FirExpression.superQualifierSymbol(callSymbol: IrSymbol?): IrClassSymbol? { + if (this !is FirQualifiedAccess) { + return null + } + val dispatchReceiverReference = calleeReference + if (dispatchReceiverReference !is FirSuperReference) { + return null + } + val superTypeRef = dispatchReceiverReference.superTypeRef + val coneSuperType = superTypeRef.coneTypeSafe() + if (coneSuperType != null) { + val firClassSymbol = coneSuperType.lookupTag.toSymbol(session) as? FirClassSymbol<*> + if (firClassSymbol != null) { + return classifierStorage.getIrClassSymbol(firClassSymbol) + } + } else if (superTypeRef is FirComposedSuperTypeRef) { + val owner = callSymbol?.owner + if (owner != null && owner is IrDeclaration) { + return owner.parentClassOrNull?.symbol + } + } + return null + } + fun convertToIrCall( qualifiedAccess: FirQualifiedAccess, typeRef: FirTypeRef, @@ -385,25 +409,6 @@ class CallAndReferenceGenerator( return@convertWithOffsets visitor.convertToIrExpression(dispatchReceiver) } } - var superQualifierSymbol: IrClassSymbol? = null - if (dispatchReceiver is FirQualifiedAccess) { - val dispatchReceiverReference = dispatchReceiver.calleeReference - if (dispatchReceiverReference is FirSuperReference) { - val superTypeRef = dispatchReceiverReference.superTypeRef - val coneSuperType = superTypeRef.coneTypeSafe() - if (coneSuperType != null) { - val firClassSymbol = coneSuperType.lookupTag.toSymbol(session) as? FirClassSymbol<*> - if (firClassSymbol != null) { - superQualifierSymbol = classifierStorage.getIrClassSymbol(firClassSymbol) - } - } else if (superTypeRef is FirComposedSuperTypeRef) { - val owner = symbol?.owner - if (owner != null && owner is IrDeclaration) { - superQualifierSymbol = owner.parentClassOrNull?.symbol - } - } - } - } when (symbol) { is IrConstructorSymbol -> IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, symbol) is IrSimpleFunctionSymbol -> { @@ -412,7 +417,7 @@ class CallAndReferenceGenerator( typeArgumentsCount = symbol.owner.typeParameters.size, valueArgumentsCount = symbol.owner.valueParameters.size, origin = qualifiedAccess.calleeReference.statementOrigin(), - superQualifierSymbol = superQualifierSymbol + superQualifierSymbol = dispatchReceiver.superQualifierSymbol(symbol) ) } is IrPropertySymbol -> { @@ -424,11 +429,11 @@ class CallAndReferenceGenerator( typeArgumentsCount = getter.typeParameters.size, valueArgumentsCount = 0, origin = IrStatementOrigin.GET_PROPERTY, - superQualifierSymbol = superQualifierSymbol + superQualifierSymbol = dispatchReceiver.superQualifierSymbol(symbol) ) backingField != null -> IrGetFieldImpl( startOffset, endOffset, backingField.symbol, type, - superQualifierSymbol = superQualifierSymbol + superQualifierSymbol = dispatchReceiver.superQualifierSymbol(symbol) ) else -> IrErrorCallExpressionImpl( startOffset, endOffset, type, @@ -439,7 +444,7 @@ class CallAndReferenceGenerator( is IrFieldSymbol -> IrGetFieldImpl( startOffset, endOffset, symbol, type, origin = IrStatementOrigin.GET_PROPERTY.takeIf { qualifiedAccess.calleeReference !is FirDelegateFieldReference }, - superQualifierSymbol = superQualifierSymbol + superQualifierSymbol = dispatchReceiver.superQualifierSymbol(symbol) ) is IrValueSymbol -> IrGetValueImpl( startOffset, endOffset, type, symbol, @@ -472,12 +477,16 @@ class CallAndReferenceGenerator( startOffset, endOffset, type, setter.symbol, typeArgumentsCount = setter.typeParameters.size, valueArgumentsCount = 1, - origin = origin + origin = origin, + superQualifierSymbol = variableAssignment.dispatchReceiver.superQualifierSymbol(symbol) ).apply { putValueArgument(0, assignedValue) } - backingField != null -> IrSetFieldImpl(startOffset, endOffset, backingField.symbol, type).apply { - // NB: to be consistent with FIR2IR, origin should be null here + backingField != null -> IrSetFieldImpl( + startOffset, endOffset, backingField.symbol, type, + origin = null, // NB: to be consistent with PSI2IR, origin should be null here + superQualifierSymbol = variableAssignment.dispatchReceiver.superQualifierSymbol(symbol) + ).apply { value = assignedValue } else -> generateErrorCallExpression(startOffset, endOffset, calleeReference) diff --git a/compiler/testData/codegen/box/super/basicproperty.kt b/compiler/testData/codegen/box/super/basicproperty.kt index a763c7a82d8..f1fab6ffe23 100644 --- a/compiler/testData/codegen/box/super/basicproperty.kt +++ b/compiler/testData/codegen/box/super/basicproperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class M() { open var b: Int = 0 } diff --git a/compiler/testData/codegen/box/super/enclosedVar.kt b/compiler/testData/codegen/box/super/enclosedVar.kt index 634b8d34ddc..50477570820 100644 --- a/compiler/testData/codegen/box/super/enclosedVar.kt +++ b/compiler/testData/codegen/box/super/enclosedVar.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR open class M() { open var y = 500 } diff --git a/compiler/testData/codegen/box/super/traitproperty.kt b/compiler/testData/codegen/box/super/traitproperty.kt index 08c5be4a23c..a5de71c24eb 100644 --- a/compiler/testData/codegen/box/super/traitproperty.kt +++ b/compiler/testData/codegen/box/super/traitproperty.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface M { var backingB : Int var b : Int diff --git a/compiler/testData/codegen/box/traits/kt5393_property.kt b/compiler/testData/codegen/box/traits/kt5393_property.kt index 9a274b99008..881fb3ba8ca 100644 --- a/compiler/testData/codegen/box/traits/kt5393_property.kt +++ b/compiler/testData/codegen/box/traits/kt5393_property.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR var result = "Fail" interface A {