Files
kotlin-fork/compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfCrossinlineSuspend.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

93 lines
1.9 KiB
Kotlin
Vendored

// WITH_COROUTINES
// WITH_STDLIB
// FILE: test.kt
import kotlin.coroutines.*
import helpers.*
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
// Are suspend calls possible inside lambda matching to the parameter
inline fun test1(crossinline runner: suspend () -> Unit) {
val l : suspend () -> Unit = { runner() }
builder { l() }
}
interface SuspendRunnable {
suspend fun run()
}
inline fun test2(crossinline c: suspend () -> Unit) {
val sr = object: SuspendRunnable {
override suspend fun run() {
c()
}
}
builder { sr.run() }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
// FILE: box.kt
suspend fun calculate() = "OK"
fun box(): String {
var res = "FAIL 1"
test1 {
res = calculate()
}
if (res != "OK") return res
res = "FAIL 2"
test1 {
test1 {
test1 {
test1 {
test1 {
test1 {
res = calculate()
}
}
}
}
}
}
if (res != "OK") return res
res = "FAIL 3"
test2 {
res = calculate()
}
if (res != "OK") return res
res = "FAIL 4"
test2 {
test2 {
test2 {
test2 {
test2 {
test2 {
res = calculate()
}
}
}
}
}
}
if (res != "OK") return res
res = "FAIL 5"
test1 {
test2 {
test1 {
test2 {
test1 {
test2 {
res = calculate()
}
}
}
}
}
}
return res
}