diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index b34b88152b6..0dcf8831869 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -16584,6 +16584,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/simpleCall.kt"); } + @Test + @TestMetadata("suspendContextualWithExtension.kt") + public void testSuspendContextualWithExtension() throws Exception { + runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/suspendContextualWithExtension.kt"); + } + @Test @TestMetadata("this.kt") public void testThis() throws Exception { 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 7c738da1489..28daa9c6792 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 @@ -402,6 +402,7 @@ private fun IrSimpleFunction.createSuspendFunctionStub(context: JvmBackendContex function.annotations += annotations function.metadata = metadata + function.contextReceiverParametersCount = contextReceiverParametersCount function.copyAttributes(this) function.copyTypeParametersFrom(this) diff --git a/compiler/testData/codegen/box/extensionFunctions/contextReceivers/suspendContextualWithExtension.kt b/compiler/testData/codegen/box/extensionFunctions/contextReceivers/suspendContextualWithExtension.kt new file mode 100644 index 00000000000..0c6e74c9ca1 --- /dev/null +++ b/compiler/testData/codegen/box/extensionFunctions/contextReceivers/suspendContextualWithExtension.kt @@ -0,0 +1,39 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_COROUTINES +// WITH_STDLIB +// FIR status: context receivers aren't yet supported + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +class Context { + fun c() = "O" +} + +class Extension { + fun e() = "K" +} + +context(Context) +suspend fun Extension.suspendingTest() = c() + e() + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var result = "fail" + + builder { + with(Extension()) { + with(Context()) { + result = suspendingTest() + } + } + } + + return result +} \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 4f1fe4f96e4..c332a993511 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -16584,6 +16584,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/simpleCall.kt"); } + @Test + @TestMetadata("suspendContextualWithExtension.kt") + public void testSuspendContextualWithExtension() throws Exception { + runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/suspendContextualWithExtension.kt"); + } + @Test @TestMetadata("this.kt") public void testThis() throws Exception {