159d292ea7
* unify various checks for whether a suspend function needs a
continuation;
* mark the continuation parameter with an origin (this also allows
correctly computing the offset of the local in codegen -- see the
new test);
* when wrapping `suspend fun main`, use a suspend reference instead of
a synthetic non-suspend lambda (required to correctly implement the
previous point, as previously the continuation parameter was passed
to main() itself correctly only because of very lenient checks in
AddContinuationLowering).
23 lines
531 B
Kotlin
Vendored
23 lines
531 B
Kotlin
Vendored
// WITH_RUNTIME
|
|
// WITH_COROUTINES
|
|
// TARGET_BACKEND: JVM
|
|
// FILE: a.kt
|
|
|
|
inline suspend fun f(crossinline lambda: suspend (Double) -> Double): Double {
|
|
val obj = object {
|
|
suspend fun g(x: Double): Double = lambda(x)
|
|
}
|
|
return obj.g(1.0)
|
|
}
|
|
|
|
// FILE: b.kt
|
|
import helpers.*
|
|
import kotlin.coroutines.*
|
|
import kotlin.coroutines.intrinsics.*
|
|
|
|
fun box(): String {
|
|
var result: Double = 0.0
|
|
suspend { result = f { it } }.startCoroutine(EmptyContinuation)
|
|
return if (result == 1.0) "OK" else "fail: $result"
|
|
}
|