Generate last expression in coroutine block even for Unit expected type

This commit is contained in:
Denis Zharkov
2016-06-17 19:02:04 +03:00
parent 96eb3f411d
commit 5ee33e6ad5
3 changed files with 34 additions and 1 deletions
@@ -0,0 +1,26 @@
class Controller {
var ok = false
var v = "fail"
suspend fun suspendHere(v: String, x: Continuation<Unit>) {
this.v = v
x.resume(Unit)
}
operator fun handleResult(u: Unit, v: Continuation<Nothing>) {
ok = true
}
}
fun builder(coroutine c: Controller.() -> Continuation<Unit>): String {
val controller = Controller()
c(controller).resume(Unit)
if (!controller.ok) throw java.lang.RuntimeException("Fail 1")
return controller.v
}
fun box(): String {
return builder {
suspendHere("OK")
}
}