From 7ec9d608cc42dacc22439b28bde123b41442e55e Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Fri, 15 Oct 2021 05:53:08 +0200 Subject: [PATCH] Use original instead of lowered suspend function as a key to view. Otherwise, SAM conversions will break. #KT-49294 Fixed --- .../kotlin/backend/jvm/lower/AddContinuationLowering.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index 4eb5247983e..11faed50a26 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.backend.jvm.codegen.hasContinuation import org.jetbrains.kotlin.backend.jvm.codegen.isInvokeSuspendOfContinuation import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface import org.jetbrains.kotlin.backend.jvm.ir.defaultValue +import org.jetbrains.kotlin.backend.jvm.ir.suspendFunctionOriginal import org.jetbrains.kotlin.backend.jvm.localDeclarationsPhase import org.jetbrains.kotlin.codegen.coroutines.* import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX @@ -384,7 +385,9 @@ private class AddContinuationLowering(context: JvmBackendContext) : SuspendLower // the result is called 'view', just to be consistent with old backend. private fun IrSimpleFunction.suspendFunctionViewOrStub(context: JvmBackendContext): IrSimpleFunction { if (!isSuspend) return this - return context.suspendFunctionOriginalToView.getOrPut(this) { createSuspendFunctionStub(context) } + // We need to use suspend function originals here, since if we use 'this' here, + // turing FlowCollector into 'fun interface' leads to AbstractMethodError + return context.suspendFunctionOriginalToView.getOrPut(suspendFunctionOriginal()) { createSuspendFunctionStub(context) } } private fun IrSimpleFunction.createSuspendFunctionStub(context: JvmBackendContext): IrSimpleFunction {