diff --git a/compiler/testData/codegen/box/coroutines/dispatchResume.kt b/compiler/testData/codegen/box/coroutines/dispatchResume.kt index a08643483c7..2fd19636969 100644 --- a/compiler/testData/codegen/box/coroutines/dispatchResume.kt +++ b/compiler/testData/codegen/box/coroutines/dispatchResume.kt @@ -3,6 +3,7 @@ // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST +// FULL_JDK import helpers.* import COROUTINES_PACKAGE.* import COROUTINES_PACKAGE.intrinsics.* @@ -11,16 +12,20 @@ class Controller { var log = "" var resumeIndex = 0 - suspend fun suspendWithValue(value: T): T = suspendCoroutineOrReturn { continuation -> + var callback: (() -> Unit)? = null + + suspend fun suspendWithValue(value: T): T = suspendCoroutine { continuation -> log += "suspend($value);" - continuation.resume(value) - COROUTINE_SUSPENDED + callback = { + continuation.resume(value) + } } - suspend fun suspendWithException(value: String): Unit = suspendCoroutineOrReturn { continuation -> + suspend fun suspendWithException(value: String): Unit = suspendCoroutine { continuation -> log += "error($value);" - continuation.resumeWithException(RuntimeException(value)) - COROUTINE_SUSPENDED + callback = { + continuation.resumeWithException(RuntimeException(value)) + } } } @@ -71,6 +76,13 @@ fun test(c: suspend Controller.() -> Unit): String { return true } })) + + while (controller.callback != null) { + val c = controller.callback!! + controller.callback = null + c() + } + return controller.log } @@ -80,7 +92,7 @@ fun box(): String { val k = suspendWithValue("K") log += "$o$k;" } - if (result != "before 0;suspend(O);before 1;suspend(K);before 2;OK;after 2;after 1;after 0;") return "fail1: $result" + if (result != "before 0;suspend(O);after 0;before 1;suspend(K);after 1;before 2;OK;after 2;") return "fail1: $result" result = test { try { @@ -91,7 +103,7 @@ fun box(): String { log += "${e.message};" } } - if (result != "before 0;error(OK);before 1;OK;after 1;after 0;") return "fail2: $result" + if (result != "before 0;error(OK);after 0;before 1;OK;after 1;") return "fail2: $result" return "OK" } diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt index 28a7334e980..2f88fc13704 100644 --- a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/dispatchResume.kt @@ -3,6 +3,7 @@ // WITH_RUNTIME // WITH_COROUTINES // COMMON_COROUTINES_TEST +// FULL_JDK import helpers.* import COROUTINES_PACKAGE.* import COROUTINES_PACKAGE.intrinsics.* @@ -11,16 +12,20 @@ class Controller { var log = "" var resumeIndex = 0 - suspend fun suspendWithValue(value: T): T = suspendCoroutineOrReturn { continuation -> + var callback: (() -> Unit)? = null + + suspend fun suspendWithValue(value: T): T = suspendCoroutine { continuation -> log += "suspend($value);" - continuation.resume(value) - COROUTINE_SUSPENDED + callback = { + continuation.resume(value) + } } - suspend fun suspendWithException(value: String): Unit = suspendCoroutineOrReturn { continuation -> + suspend fun suspendWithException(value: String): Unit = suspendCoroutine { continuation -> log += "error($value);" - continuation.resumeWithException(RuntimeException(value)) - COROUTINE_SUSPENDED + callback = { + continuation.resumeWithException(RuntimeException(value)) + } } } @@ -31,8 +36,8 @@ abstract class ContinuationDispatcher : AbstractCoroutineContextElement(Continua } private class DispatchedContinuation( - val dispatcher: ContinuationDispatcher, - val continuation: Continuation + val dispatcher: ContinuationDispatcher, + val continuation: Continuation ): ContinuationAdapter() { override val context: CoroutineContext = continuation.context @@ -71,6 +76,13 @@ fun test(c: suspend Controller.() -> Unit): String { return true } })) + + while (controller.callback != null) { + val c = controller.callback!! + controller.callback = null + c() + } + return controller.log } @@ -98,12 +110,12 @@ fun box(): String { var result = test { test1() } - if (result != "before 0;suspend();before 1;suspend(O);before 2;suspend(K);before 3;OK;after 3;after 2;after 1;after 0;") return "fail1: $result" + if (result != "before 0;suspend();after 0;before 1;suspend(O);after 1;before 2;suspend(K);after 2;before 3;OK;after 3;") return "fail1: $result" result = test { test2() } - if (result != "before 0;suspend();before 1;suspend(O);before 2;error(OK);before 3;OK;after 3;after 2;after 1;after 0;") return "fail2: $result" + if (result != "before 0;suspend();after 0;before 1;suspend(O);after 1;before 2;error(OK);after 2;before 3;OK;after 3;") return "fail2: $result" return "OK" }