Write metadata for suspend function into anonymous coroutine classes

To render nice Kotlin types in toString() of continuation
This commit is contained in:
Alexander Udalov
2017-06-29 21:07:04 +03:00
parent 5a8546519a
commit d97fa604e1
6 changed files with 58 additions and 3 deletions
@@ -0,0 +1,33 @@
// TARGET_BACKEND: JVM
// WITH_REFLECT
// WITH_COROUTINES
import helpers.*
import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.intrinsics.*
class A<T : String> {
suspend fun foo() {}
suspend fun bar(): T {
foo()
return suspendCoroutineOrReturn { x ->
x.resume(x.toString() as T)
COROUTINE_SUSPENDED
}
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = ""
builder {
result = A<String>().bar()
}
return if (result == "(kotlin.coroutines.experimental.Continuation<T>) -> kotlin.Any?") "OK" else "Fail: $result"
}