Minor. Add regression tests

#KT-44143
This commit is contained in:
Ilmir Usmanov
2021-03-31 19:52:30 +02:00
committed by TeamCityServer
parent 03fed85447
commit 786999bcfe
11 changed files with 327 additions and 5 deletions
@@ -0,0 +1,40 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND: JS_IR
import kotlin.coroutines.*
interface GenericSuspendInterface<T> {
suspend fun execute(): T
}
interface SuspendInterface : GenericSuspendInterface<Result<String>>
class SuspendImpl : SuspendInterface {
override suspend fun execute(): Result<String> = Result.success("OK")
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL 1"
builder {
val impl = SuspendImpl()
val implResult = impl.execute()
res = implResult.getOrThrow()
}
if (res != "OK") return res
res = "FAIL 2"
builder {
val iface: SuspendInterface = SuspendImpl()
val result = iface.execute()
res = result.getOrThrow()
}
return res
}
@@ -0,0 +1,43 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JS_IR
import kotlin.coroutines.*
interface GenericSuspendInterface<T> {
suspend fun execute(): T
}
interface SuspendInterface : GenericSuspendInterface<Result<String>>
var c: Continuation<Result<String>>? = null
class SuspendImpl : SuspendInterface {
override suspend fun execute(): Result<String> = suspendCoroutine { c = it }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL 1"
builder {
val impl = SuspendImpl()
val implResult = impl.execute()
res = implResult.getOrThrow()
}
c?.resume(Result.success("OK"))
if (res != "OK") return res
res = "FAIL 2"
builder {
val iface: SuspendInterface = SuspendImpl()
val result = iface.execute()
res = result.getOrThrow()
}
c?.resume(Result.success("OK"))
return res
}
@@ -0,0 +1,43 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JS_IR
import kotlin.coroutines.*
interface GenericSuspendInterface<T> {
suspend fun execute(): T
}
interface SuspendInterface : GenericSuspendInterface<Result<String>>
var c: Continuation<Result<String>>? = null
var res = "FAIL 1"
class SuspendImpl : SuspendInterface {
override suspend fun execute(): Result<String> = suspendCoroutine { c = it }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
res = it.exceptionOrNull()!!.message!!
})
}
fun box(): String {
builder {
val impl = SuspendImpl()
val implResult = impl.execute()
implResult.getOrThrow()
}
c?.resumeWithException(IllegalStateException("OK"))
if (res != "OK") return res
res = "FAIL 2"
builder {
val iface: SuspendInterface = SuspendImpl()
val result = iface.execute()
result.getOrThrow()
}
c?.resumeWithException(IllegalStateException("OK"))
return res
}