From 76f78d3fde0d0969e190d3fcd79f74f3a7827293 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 11 Feb 2020 15:25:00 +0300 Subject: [PATCH] FIR2IR: don't mutate basic FIR for invoke / next calls --- .../kotlin/fir/backend/Fir2IrVisitor.kt | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 293e564b018..8d1efc11515 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -889,28 +889,27 @@ class Fir2IrVisitor( val convertibleCall = if (functionCall.toResolvedCallableSymbol()?.fir is FirIntegerOperator) { functionCall.copy().transformSingle(integerApproximator, null) } else { - checkIfInvoke(functionCall) + functionCall.replaceCalleeReferenceWithOverridden() } return convertibleCall.toIrExpression(convertibleCall.typeRef) .applyCallArguments(convertibleCall).applyTypeArguments(convertibleCall).applyReceivers(convertibleCall) } - // Use the generic invoke method in Function classes, to match bridges generated by the backend. - private fun checkIfInvoke(functionCall: FirFunctionCall): FirFunctionCall { - if (functionCall !is FirFunctionCallImpl) { - return functionCall - } - val calleeReference = (functionCall.calleeReference as? FirResolvedNamedReference) ?: return functionCall - val resolvedSymbol = (calleeReference.resolvedSymbol as? FirNamedFunctionSymbol) ?: return functionCall + // Use the generic invoke & next methods to match bridges generated by the backend. + private fun FirFunctionCall.replaceCalleeReferenceWithOverridden(): FirFunctionCall { + val calleeReference = (calleeReference as? FirResolvedNamedReference) ?: return this + val resolvedSymbol = (calleeReference.resolvedSymbol as? FirNamedFunctionSymbol) ?: return this + val overriddenSymbol = resolvedSymbol.overriddenSymbol ?: return this if (resolvedSymbol.callableId.isInvoke() || resolvedSymbol.callableId.isIteratorNext()) { - functionCall.calleeReference = - buildResolvedNamedReference { + return copy( + calleeReference = buildResolvedNamedReference { source = calleeReference.source name = calleeReference.name - this.resolvedSymbol = resolvedSymbol.overriddenSymbol!! + this.resolvedSymbol = overriddenSymbol } + ) } - return functionCall + return this } override fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: Any?): IrElement {