From add2ca1d1107aeacc7d8a3210b999dc2f1bd015c Mon Sep 17 00:00:00 2001 From: Anastasiya Shadrina Date: Fri, 22 Oct 2021 00:45:46 +0700 Subject: [PATCH] [Tests] Try structured concurrency with context receivers --- .../FirBlackBoxCodegenTestGenerated.java | 6 +++ .../fromKEEP/structuredConcurrency.kt | 41 +++++++++++++++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 +++ 3 files changed, 53 insertions(+) create mode 100644 compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/structuredConcurrency.kt 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 184b83bfc1f..1667ca81fb2 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 @@ -16255,6 +16255,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testMonoidSum() throws Exception { runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/monoidSum.kt"); } + + @Test + @TestMetadata("structuredConcurrency.kt") + public void testStructuredConcurrency() throws Exception { + runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/structuredConcurrency.kt"); + } } } } diff --git a/compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/structuredConcurrency.kt b/compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/structuredConcurrency.kt new file mode 100644 index 00000000000..f26345b307d --- /dev/null +++ b/compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/structuredConcurrency.kt @@ -0,0 +1,41 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// WITH_RUNTIME +// WITH_COROUTINES + +import helpers.* +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +interface CoroutineScope +object MyCoroutineScope : CoroutineScope + +interface Flow { + suspend fun collect(): String +} + +inline fun flow(crossinline block: suspend () -> String) = object : Flow { + override suspend fun collect(): String = block() +} + +fun CoroutineScope.launch(c: suspend () -> String): String { + var result: String = "fail" + c.startCoroutine(handleResultContinuation { value -> + result = value + }) + return result +} + +context(CoroutineScope) +fun Flow.launchFlow() = launch { collect() } + +fun simpleFlow(): Flow = flow { + "OK" +} + +fun box(): String { + return with(MyCoroutineScope) { + simpleFlow().launchFlow() + } +} \ 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 50b628b01f7..06ec57afeb4 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 @@ -16255,6 +16255,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testMonoidSum() throws Exception { runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/monoidSum.kt"); } + + @Test + @TestMetadata("structuredConcurrency.kt") + public void testStructuredConcurrency() throws Exception { + runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/structuredConcurrency.kt"); + } } } }