From 0e243ca29594b066860da8b1ae662d9b05db4c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Thu, 6 Feb 2020 10:50:05 +0100 Subject: [PATCH] JVM IR: Fix receiver types in AddContinuationLowering --- .../jvm/lower/AddContinuationLowering.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index fb3bd104627..7b9e1b0eea3 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -12,11 +12,11 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin -import org.jetbrains.kotlin.backend.jvm.ir.IrInlineReferenceLocator -import org.jetbrains.kotlin.backend.jvm.ir.defaultValue import org.jetbrains.kotlin.backend.jvm.codegen.isInvokeSuspendForInlineOfLambda import org.jetbrains.kotlin.backend.jvm.codegen.isInvokeSuspendOfContinuation import org.jetbrains.kotlin.backend.jvm.codegen.isInvokeSuspendOfLambda +import org.jetbrains.kotlin.backend.jvm.ir.IrInlineReferenceLocator +import org.jetbrains.kotlin.backend.jvm.ir.defaultValue import org.jetbrains.kotlin.backend.jvm.localDeclarationsPhase import org.jetbrains.kotlin.codegen.coroutines.* import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX @@ -73,6 +73,18 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : return super.visitFunction(declaration).also { functionStack.pop() } } + override fun visitMemberAccess(expression: IrMemberAccessExpression): IrExpression { + val receiverType = expression.dispatchReceiver?.type + val newExpression = super.visitMemberAccess(expression) as IrMemberAccessExpression + if (receiverType != null && receiverType != newExpression.dispatchReceiver?.type) { + newExpression.dispatchReceiver = IrTypeOperatorCallImpl( + expression.startOffset, expression.endOffset, receiverType, + IrTypeOperator.IMPLICIT_CAST, receiverType, newExpression.dispatchReceiver!! + ) + } + return newExpression + } + override fun visitCall(expression: IrCall): IrExpression { // This is a property, no need to add continuation parameter, since this cannot be suspend call if (functionStack.isEmpty()) return super.visitCall(expression) @@ -825,4 +837,4 @@ private fun IrCall.createSuspendFunctionCallViewIfNeeded(context: JvmBackendCont } } } -} \ No newline at end of file +}