JVM IR: IC coroutines: return boxed type from suspend function if

the function overrides function, returning type argument
 #KT-45451 Fixed
This commit is contained in:
Ilmir Usmanov
2021-03-23 20:49:08 +01:00
parent 0aca68e7c7
commit 5e6f52009f
11 changed files with 250 additions and 10 deletions
@@ -0,0 +1,35 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JVM
import kotlin.coroutines.*
interface EntityBase<out ID> {
suspend fun id(): ID
}
inline class EntityId(val value: String)
interface Entity : EntityBase<EntityId>
class EntityStub : Entity {
override suspend fun id(): EntityId = EntityId("OK")
}
suspend fun test(): EntityId {
val entity: Entity = EntityStub()
return entity.id()
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL"
builder {
res = test().value
}
return res
}
@@ -0,0 +1,37 @@
// WITH_RUNTIME
import kotlin.coroutines.*
interface EntityBase<out ID> {
suspend fun id(): ID
}
inline class EntityId(val value: String)
interface Entity : EntityBase<EntityId>
var c: Continuation<EntityId>? = null
class EntityStub : Entity {
override suspend fun id(): EntityId = suspendCoroutine { c = it }
}
suspend fun test(): EntityId {
val entity: Entity = EntityStub()
return entity.id()
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL"
builder {
res = test().value
}
c?.resume(EntityId("OK"))
return res
}
@@ -0,0 +1,35 @@
// WITH_RUNTIME
import kotlin.coroutines.*
interface EntityBase<out ID> {
suspend fun id(): ID
}
inline class EntityId(val value: String)
interface Entity : EntityBase<EntityId>
var res = "FAIL"
class EntityStub : Entity {
override suspend fun id(): EntityId = error("OK")
}
suspend fun test(): EntityId {
val entity: Entity = EntityStub()
return entity.id()
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
res = it.exceptionOrNull()!!.message!!
})
}
fun box(): String {
builder {
test().value
}
return res
}