From a23ce42c8042438c8bb2c6f393cefc7df16e6f5e Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 4 Jul 2018 18:40:14 +0300 Subject: [PATCH] Replace a couple of usages of suspendCoroutineOrReturn in tests --- ...outineUninterceptedOrReturnInterception.kt | 19 +++++++++++++------ .../coroutinesBinary.kt | 13 +++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/compiler/testData/codegen/box/coroutines/intrinsicSemantics/startCoroutineUninterceptedOrReturnInterception.kt b/compiler/testData/codegen/box/coroutines/intrinsicSemantics/startCoroutineUninterceptedOrReturnInterception.kt index 02ee5b850d7..fc32d370b11 100644 --- a/compiler/testData/codegen/box/coroutines/intrinsicSemantics/startCoroutineUninterceptedOrReturnInterception.kt +++ b/compiler/testData/codegen/box/coroutines/intrinsicSemantics/startCoroutineUninterceptedOrReturnInterception.kt @@ -8,17 +8,22 @@ import COROUTINES_PACKAGE.* import COROUTINES_PACKAGE.intrinsics.* import kotlin.test.assertEquals -suspend fun suspendHere(): String = suspendCoroutineOrReturn { x -> - x.resume("OK") - COROUTINE_SUSPENDED +var callback: () -> Unit = {} + +suspend fun suspendHere(): String = suspendCoroutine { x -> + callback = { + x.resume("OK") + } } -suspend fun suspendWithException(): String = suspendCoroutineOrReturn { x -> - x.resumeWithException(RuntimeException("OK")) - COROUTINE_SUSPENDED +suspend fun suspendWithException(): String = suspendCoroutine { x -> + callback = { + x.resumeWithException(RuntimeException("OK")) + } } fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String): String { + callback = {} var fromSuspension: String? = null var counter = 0 @@ -39,6 +44,8 @@ fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String) "Exception: ${e.message}" } + callback() + if (counter != expectedCount) throw RuntimeException("fail 0") if (shouldSuspend) { diff --git a/compiler/testData/compileKotlinAgainstKotlin/coroutinesBinary.kt b/compiler/testData/compileKotlinAgainstKotlin/coroutinesBinary.kt index 5aa06559775..a1ae46d8761 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/coroutinesBinary.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/coroutinesBinary.kt @@ -9,19 +9,24 @@ import COROUTINES_PACKAGE.* import COROUTINES_PACKAGE.intrinsics.* class Controller { - suspend fun suspendHere() = suspendCoroutineOrReturn { x -> - x.resume("OK") - COROUTINE_SUSPENDED + var callback: () -> Unit = {} + suspend fun suspendHere() = suspendCoroutine { x -> + callback = { + x.resume("OK") + } } } fun builder(c: suspend Controller.() -> Unit) { - c.startCoroutine(Controller(), object : helpers.ContinuationAdapter() { + val controller = Controller() + c.startCoroutine(controller, object : helpers.ContinuationAdapter() { override val context: CoroutineContext = EmptyCoroutineContext override fun resume(value: Unit) {} override fun resumeWithException(exception: Throwable) {} }) + + controller.callback() } // FILE: B.kt