Minor. Make test actually suspend and add a test without suspension

This commit is contained in:
Ilmir Usmanov
2021-04-22 13:26:27 +02:00
parent 23ffbe4d9e
commit f7a9bc3521
11 changed files with 128 additions and 7 deletions
@@ -0,0 +1,26 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
// FILE: a.kt
@file:JvmMultifileClass
@file:JvmName("A")
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
@Suppress("UNSUPPORTED_FEATURE")
inline class I(val x: Any?)
suspend fun <T> suspendHere(t: T): T = t
suspend fun f(): I = I(suspendHere("OK"))
// FILE: z.kt
import helpers.*
import kotlin.coroutines.*
fun box(): String {
var result = "fail"
suspend { result = f().x as String }.startCoroutine(EmptyContinuation)
return result
}
@@ -0,0 +1,27 @@
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JS_IR
import helpers.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
@Suppress("UNSUPPORTED_FEATURE")
inline class I(val x: Any?)
class C {
private suspend fun f(): I {
return I("OK")
}
fun g() = suspend { f() }
}
val c: Continuation<Unit>? = null
fun box(): String {
var result = "fail"
suspend { result = C().g()().x as String }.startCoroutine(EmptyContinuation)
return result
}
@@ -1,4 +1,4 @@
// TARGET_PLATFORM: JVM
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
// FILE: a.kt
@@ -11,12 +11,14 @@ import kotlin.coroutines.intrinsics.*
@Suppress("UNSUPPORTED_FEATURE")
inline class I(val x: Any?)
suspend fun <T> suspendHere(x: T): T = suspendCoroutineUninterceptedOrReturn {
it.resume(x)
suspend fun <T> suspendHere(): T = suspendCoroutineUninterceptedOrReturn {
c = it as Continuation<Any?>
COROUTINE_SUSPENDED
}
suspend fun f(): I = I(suspendHere("OK"))
var c: Continuation<Any?>? = null
suspend fun f(): I = I(suspendHere<String>())
// FILE: z.kt
import helpers.*
@@ -25,5 +27,6 @@ import kotlin.coroutines.*
fun box(): String {
var result = "fail"
suspend { result = f().x as String }.startCoroutine(EmptyContinuation)
c?.resume("OK")
return result
}
@@ -8,13 +8,15 @@ import kotlin.coroutines.intrinsics.*
@Suppress("UNSUPPORTED_FEATURE")
inline class I(val x: Any?)
suspend fun <T> suspendHere(x: T): T = suspendCoroutineUninterceptedOrReturn {
it.resume(x)
suspend fun <T> suspendHere(): T = suspendCoroutineUninterceptedOrReturn {
c = it as Continuation<Any?>
COROUTINE_SUSPENDED
}
var c: Continuation<Any?>? = null
class C {
private suspend fun f(): I = I(suspendHere("OK"))
private suspend fun f(): I = I(suspendHere<String>())
fun g() = suspend { f() }
}
@@ -22,5 +24,7 @@ class C {
fun box(): String {
var result = "fail"
suspend { result = C().g()().x as String }.startCoroutine(EmptyContinuation)
c?.resume("OK")
return result
}