[Tests] Try structured concurrency with context receivers

This commit is contained in:
Anastasiya Shadrina
2021-10-22 00:45:46 +07:00
committed by TeamCityServer
parent 097e286622
commit add2ca1d11
3 changed files with 53 additions and 0 deletions
@@ -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");
}
}
}
}
@@ -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<out T> {
suspend fun collect(): String
}
inline fun <T : Any> flow(crossinline block: suspend () -> String) = object : Flow<T> {
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 <T> Flow<T>.launchFlow() = launch { collect() }
fun simpleFlow(): Flow<String> = flow {
"OK"
}
fun box(): String {
return with(MyCoroutineScope) {
simpleFlow().launchFlow()
}
}
@@ -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");
}
}
}
}