Files
kotlin-fork/compiler/testData/codegen/boxInline/suspend/inlineOrdinaryOfCrossinlineSuspend.kt
T
Ilmir Usmanov f60787d57c Move coroutines to kotlin.coroutines package: tests
Introduce COMMON_COROUTINES_TEST directive.
Every test with this directive is run twice: one time with
language version 1.2 and kotlin.coroutines.experimental package
and the other time with language version 1.3 and kotlin.coroutines
package. Each run is a separate method: with suffixes _1_2 and _1_3
respectively.
However, since codegen of release coroutines is not supported in JS
backend, we generate only one method: with suffix _1_2.
 #KT-23362
2018-04-23 21:51:59 +03:00

104 lines
2.2 KiB
Kotlin
Vendored

// FILE: test.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
import COROUTINES_PACKAGE.*
// 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(object: Continuation<Unit> {
override val context: CoroutineContext
get() = EmptyCoroutineContext
override fun resume(value: Unit) {
}
override fun resumeWithException(exception: Throwable) {
throw exception
}
})
}
// FILE: box.kt
// COMMON_COROUTINES_TEST
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
}