IC & Coroutines: Unbox inline class parameter of suspend lambda

inside 'create' if 'create' overrides 'create' from
BaseContinuationImpl. In other words, unbox the parameter if 'create'
accepts only one parameter.

 #KT-43249 Fixed
 #KT-43533 Fixed
This commit is contained in:
Ilmir Usmanov
2020-11-26 03:48:44 +01:00
parent eba260f681
commit 4e334217a8
11 changed files with 218 additions and 6 deletions
@@ -0,0 +1,26 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
import kotlin.coroutines.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
inline class IC(val s: String)
suspend fun <T> List<T>.onEach(c: suspend (T) -> Unit) {
for (e in this) {
c(e)
}
}
fun box(): String {
var res = ""
builder {
listOf(IC("O"), IC("K")).onEach { res += it.s }
}
return res
}
@@ -0,0 +1,33 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
import kotlin.coroutines.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
inline class IC(val s: String)
suspend fun <T> List<T>.onEach(c: suspend (T) -> Unit) {
for (e in this) {
c(e)
}
}
var c: Continuation<Any>? = null
fun box(): String {
var res = ""
builder {
listOf(IC("O"), IC("K")).onEach { res += suspendCoroutine<String> { cont ->
@Suppress("UNCHECKED_CAST")
c = cont as Continuation<Any>
}}
}
c?.resume("O")
c?.resume("K")
return res
}
@@ -0,0 +1,35 @@
// WITH_RUNTIME
// WITH_COROUTINES
// KJS_WITH_FULL_RUNTIME
import kotlin.coroutines.*
import helpers.*
var result = "FAIL"
fun builder(c: suspend () -> Unit) {
c.startCoroutine(handleExceptionContinuation {
result = it.message!!
})
}
inline class IC(val s: String)
suspend fun <T> List<T>.onEach(c: suspend (T) -> Unit) {
for (e in this) {
c(e)
}
}
var c: Continuation<Any>? = null
fun box(): String {
builder {
listOf(IC("O"), IC("K")).onEach { suspendCoroutine<String> { cont ->
@Suppress("UNCHECKED_CAST")
c = cont as Continuation<Any>
}}
}
c?.resumeWithException(IllegalStateException("OK"))
return result
}