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 4d42e89158e..64401f35c08 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 @@ -121,8 +121,10 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : val parametersFields = info.function.valueParameters.map { addField(it.name, it.type) } val parametersWithoutArguments = parametersFields.withIndex() .mapNotNull { (i, field) -> if (info.reference.getValueArgument(i) == null) field else null } - val parametersWithArguments = parametersFields - parametersWithoutArguments - val constructor = addPrimaryConstructorForLambda(info.arity, info.reference, parametersFields) + val parametersWithArguments = parametersFields.withIndex() + .filter { info.reference.getValueArgument(it.index) != null } + val fieldsForArguments = parametersWithArguments.map(IndexedValue::value) + val constructor = addPrimaryConstructorForLambda(info.arity, info.reference, fieldsForArguments) val invokeToOverride = functionNClass.functions.single { it.owner.valueParameters.size == info.arity + 1 && it.owner.name.asString() == "invoke" } @@ -140,7 +142,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : constructor, invokeSuspend, invokeToOverride, - parametersWithArguments, + fieldsForArguments, listOfNotNull(receiverField) + parametersWithoutArguments ) } @@ -308,7 +310,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : constructor: IrFunction, superType: IrClass, info: SuspendLambdaInfo, - parametersWithArguments: List, + parametersWithArguments: List>, singleParameterField: IrField? ): IrFunction { val create = superType.functions.single { @@ -323,7 +325,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) : for (typeParameter in typeParameters) { it.putTypeArgument(typeParameter.index, typeParameter.defaultType) } - for ((i, field) in parametersWithArguments.withIndex()) { + for ((i, field) in parametersWithArguments) { if (info.reference.getValueArgument(i) == null) continue it.putValueArgument(index++, irGetField(irGet(function.dispatchReceiverParameter!!), field)) } diff --git a/compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt b/compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt new file mode 100644 index 00000000000..8bd92cef3c5 --- /dev/null +++ b/compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt @@ -0,0 +1,25 @@ +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// WITH_COROUTINES + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +fun builder(c: suspend String.() -> Unit) { + c.startCoroutine("OK", EmptyContinuation) +} + +interface A { + var result: String + + fun test(): String { + builder { result = this } + return result + } +} + +fun box(): String = + object : A { + override var result = "Fail" + }.test() diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 2ef5c00e70d..54312c15332 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -7150,6 +7150,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt", "kotlin.coroutines"); } + @TestMetadata("interfaceMethodWithBody.kt") + public void testInterfaceMethodWithBody() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt"); + } + @TestMetadata("safeCallOnTwoReceiversLong.kt") public void testSafeCallOnTwoReceiversLong_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/safeCallOnTwoReceiversLong.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 1c64326cec7..2c1805314db 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7150,6 +7150,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt", "kotlin.coroutines"); } + @TestMetadata("interfaceMethodWithBody.kt") + public void testInterfaceMethodWithBody() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt"); + } + @TestMetadata("safeCallOnTwoReceiversLong.kt") public void testSafeCallOnTwoReceiversLong_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/safeCallOnTwoReceiversLong.kt", "kotlin.coroutines.experimental"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index c1eba7cc0e9..362758dc61e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -6565,6 +6565,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt", "kotlin.coroutines"); } + @TestMetadata("interfaceMethodWithBody.kt") + public void testInterfaceMethodWithBody() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt"); + } + @TestMetadata("safeCallOnTwoReceiversLong.kt") public void testSafeCallOnTwoReceiversLong_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/safeCallOnTwoReceiversLong.kt", "kotlin.coroutines"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 4a3e50f9754..029ce75627d 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -6565,6 +6565,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt", "kotlin.coroutines"); } + @TestMetadata("interfaceMethodWithBody.kt") + public void testInterfaceMethodWithBody() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt"); + } + @TestMetadata("safeCallOnTwoReceiversLong.kt") public void testSafeCallOnTwoReceiversLong_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/safeCallOnTwoReceiversLong.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index a64cb5a4ab3..b4e48ecb32e 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -5580,6 +5580,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt", "kotlin.coroutines"); } + @TestMetadata("interfaceMethodWithBody.kt") + public void testInterfaceMethodWithBody() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt"); + } + @TestMetadata("safeCallOnTwoReceiversLong.kt") public void testSafeCallOnTwoReceiversLong_1_3() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/safeCallOnTwoReceiversLong.kt", "kotlin.coroutines"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index c039679f486..b033cca244f 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -6125,6 +6125,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/inlineSuspendFinally.kt", "kotlin.coroutines"); } + @TestMetadata("interfaceMethodWithBody.kt") + public void testInterfaceMethodWithBody() throws Exception { + runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBody.kt"); + } + @TestMetadata("safeCallOnTwoReceiversLong.kt") public void testSafeCallOnTwoReceiversLong_1_2() throws Exception { runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/featureIntersection/safeCallOnTwoReceiversLong.kt", "kotlin.coroutines.experimental");