FIR2IR: don't mutate basic FIR for invoke / next calls

This commit is contained in:
Mikhail Glukhikh
2020-02-11 15:25:00 +03:00
parent 37abdb1732
commit 76f78d3fde
@@ -889,28 +889,27 @@ class Fir2IrVisitor(
val convertibleCall = if (functionCall.toResolvedCallableSymbol()?.fir is FirIntegerOperator) { val convertibleCall = if (functionCall.toResolvedCallableSymbol()?.fir is FirIntegerOperator) {
functionCall.copy().transformSingle(integerApproximator, null) functionCall.copy().transformSingle(integerApproximator, null)
} else { } else {
checkIfInvoke(functionCall) functionCall.replaceCalleeReferenceWithOverridden()
} }
return convertibleCall.toIrExpression(convertibleCall.typeRef) return convertibleCall.toIrExpression(convertibleCall.typeRef)
.applyCallArguments(convertibleCall).applyTypeArguments(convertibleCall).applyReceivers(convertibleCall) .applyCallArguments(convertibleCall).applyTypeArguments(convertibleCall).applyReceivers(convertibleCall)
} }
// Use the generic invoke method in Function classes, to match bridges generated by the backend. // Use the generic invoke & next methods to match bridges generated by the backend.
private fun checkIfInvoke(functionCall: FirFunctionCall): FirFunctionCall { private fun FirFunctionCall.replaceCalleeReferenceWithOverridden(): FirFunctionCall {
if (functionCall !is FirFunctionCallImpl) { val calleeReference = (calleeReference as? FirResolvedNamedReference) ?: return this
return functionCall val resolvedSymbol = (calleeReference.resolvedSymbol as? FirNamedFunctionSymbol) ?: return this
} val overriddenSymbol = resolvedSymbol.overriddenSymbol ?: return this
val calleeReference = (functionCall.calleeReference as? FirResolvedNamedReference) ?: return functionCall
val resolvedSymbol = (calleeReference.resolvedSymbol as? FirNamedFunctionSymbol) ?: return functionCall
if (resolvedSymbol.callableId.isInvoke() || resolvedSymbol.callableId.isIteratorNext()) { if (resolvedSymbol.callableId.isInvoke() || resolvedSymbol.callableId.isIteratorNext()) {
functionCall.calleeReference = return copy(
buildResolvedNamedReference { calleeReference = buildResolvedNamedReference {
source = calleeReference.source source = calleeReference.source
name = calleeReference.name name = calleeReference.name
this.resolvedSymbol = resolvedSymbol.overriddenSymbol!! this.resolvedSymbol = overriddenSymbol
} }
)
} }
return functionCall return this
} }
override fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: Any?): IrElement { override fun visitAnnotationCall(annotationCall: FirAnnotationCall, data: Any?): IrElement {