From f46ad102664d6da01af5278cd65e4916bee838ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steven=20Sch=C3=A4fer?= Date: Mon, 3 Feb 2020 12:42:51 +0100 Subject: [PATCH] JVM IR: Fix dispatch receiver type in InheritedDefaultMethodsOnClassesLowering --- ...InheritedDefaultMethodsOnClassesLowering.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt index cae41c764fb..6629fa2f492 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InheritedDefaultMethodsOnClassesLowering.kt @@ -32,6 +32,8 @@ import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.IrTypeOperator +import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid @@ -198,7 +200,19 @@ private class InterfaceObjectCallsLowering(val context: JvmBackendContext) : IrE if (resolved?.isMethodOfAny() != true) return super.visitCall(expression) val newSuperQualifierSymbol = context.irBuiltIns.anyClass.takeIf { expression.superQualifierSymbol != null } - return super.visitCall(irCall(expression, resolved, newSuperQualifierSymbol = newSuperQualifierSymbol)) + return super.visitCall(irCall(expression, resolved, newSuperQualifierSymbol = newSuperQualifierSymbol).apply { + dispatchReceiver?.let { receiver -> + val receiverType = resolved.parentAsClass.defaultType + dispatchReceiver = IrTypeOperatorCallImpl( + receiver.startOffset, + receiver.endOffset, + receiverType, + IrTypeOperator.IMPLICIT_CAST, + receiverType, + receiver + ) + } + }) } } @@ -229,4 +243,4 @@ internal fun IrSimpleFunction.findInterfaceImplementation(): IrSimpleFunction? { } return implementation -} \ No newline at end of file +}