Make initial continuation able to be resumed with exception
#KT-14719 Fixed
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
class Controller {
|
||||
var exception: Throwable? = null
|
||||
|
||||
operator fun handleException(t: Throwable, c: Continuation<Nothing>) {
|
||||
exception = t
|
||||
}
|
||||
|
||||
suspend fun suspendHere(x: Continuation<Any>) {}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
val controller = Controller()
|
||||
c(controller).resumeWithException(RuntimeException("OK"))
|
||||
|
||||
if (controller.exception?.message != "OK") {
|
||||
throw RuntimeException("Unexpected result: ${controller.exception?.message}")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = "OK"
|
||||
builder {
|
||||
suspendHere()
|
||||
result = "fail 1"
|
||||
}
|
||||
|
||||
builder {
|
||||
result = "fail 2"
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
class Controller {
|
||||
suspend fun suspendHere(x: Continuation<Any>) {}
|
||||
}
|
||||
|
||||
fun builder(coroutine c: Controller.() -> Continuation<Unit>) {
|
||||
try {
|
||||
val controller = Controller()
|
||||
c(controller).resumeWithException(RuntimeException("OK"))
|
||||
}
|
||||
catch(e: Exception) {
|
||||
if (e?.message != "OK") {
|
||||
throw RuntimeException("Unexpected result: ${e?.message}")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
throw RuntimeException("Exception must be thrown above")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = "OK"
|
||||
builder {
|
||||
suspendHere()
|
||||
result = "fail 1"
|
||||
}
|
||||
|
||||
builder {
|
||||
result = "fail 2"
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user