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) {
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 {