mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Use fake continuation instead of ALOAD 0 while inlining Do not generate state machine for inner lambdas and inner objects, which capture crossinline suspend lambda. #KT-19159: Fixed
129 lines
2.6 KiB
Kotlin
Vendored
129 lines
2.6 KiB
Kotlin
Vendored
// FILE: test.kt
|
|
// WITH_RUNTIME
|
|
|
|
import kotlin.coroutines.experimental.*
|
|
|
|
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
|
|
// Start coroutine call is possible
|
|
// Are suspend calls possible inside lambda matching to the parameter
|
|
|
|
inline fun test1(noinline c: suspend () -> Unit) {
|
|
val l : suspend () -> Unit = { c() }
|
|
builder { l() }
|
|
}
|
|
|
|
val EmptyContinuation = object: Continuation<Unit> {
|
|
override val context: CoroutineContext
|
|
get() = EmptyCoroutineContext
|
|
|
|
override fun resume(value: Unit) {
|
|
}
|
|
|
|
override fun resumeWithException(exception: Throwable) {
|
|
throw exception
|
|
}
|
|
}
|
|
|
|
inline fun test2(noinline c: suspend () -> Unit) {
|
|
c.startCoroutine(EmptyContinuation)
|
|
}
|
|
|
|
interface SuspendRunnable {
|
|
suspend fun run()
|
|
}
|
|
|
|
inline fun test3(noinline 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"
|
|
test2 {
|
|
res = "OK"
|
|
}
|
|
if (res != "OK") return res
|
|
res = "FAIL 3"
|
|
test3 {
|
|
res = "OK"
|
|
}
|
|
if (res != "OK") return res
|
|
res = "FAIL 4"
|
|
test1 {
|
|
test1 {
|
|
test1 {
|
|
test1 {
|
|
test1 {
|
|
test1 {
|
|
res = calculate()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (res != "OK") return res
|
|
res = "FAIL 5"
|
|
test2 {
|
|
test2 {
|
|
test2 {
|
|
test2 {
|
|
test2 {
|
|
test2 {
|
|
res = calculate()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (res != "OK") return res
|
|
res = "FAIL 6"
|
|
test3 {
|
|
test3 {
|
|
test3 {
|
|
test3 {
|
|
test3 {
|
|
test3 {
|
|
res = calculate()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (res != "OK") return res
|
|
res = "FAIL 7"
|
|
test1 {
|
|
test2 {
|
|
test3 {
|
|
test1 {
|
|
test2 {
|
|
test3 {
|
|
res = calculate()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return res
|
|
}
|