[Tests] Try structured concurrency with context receivers
This commit is contained in:
committed by
TeamCityServer
parent
097e286622
commit
add2ca1d11
+6
@@ -16255,6 +16255,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
public void testMonoidSum() throws Exception {
|
public void testMonoidSum() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/monoidSum.kt");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+41
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -16255,6 +16255,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
public void testMonoidSum() throws Exception {
|
public void testMonoidSum() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/extensionFunctions/contextReceivers/fromKEEP/monoidSum.kt");
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user