From 2da889ad1a73415f0c5598bb79d4c2e95215fe3c Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Wed, 13 May 2020 11:26:09 +0500 Subject: [PATCH] Added test on suspend conversions --- backend.native/tests/build.gradle | 6 +++++ .../codegen/coroutines/suspendConversion.kt | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 backend.native/tests/codegen/coroutines/suspendConversion.kt diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index dcd400fe26f..afa32deb940 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -1806,6 +1806,12 @@ task coroutines_functionReference_lambdaAsSuspendLambda(type: KonanLocalTest) { source = "codegen/coroutines/functionReference_lambdaAsSuspendLambda.kt" } +standaloneTest('coroutines_suspendConversion') { + goldValue = "" + source = "codegen/coroutines/suspendConversion.kt" + flags = ['-XXLanguage:+SuspendConversion'] +} + task AbstractMutableCollection(type: KonanLocalTest) { expectedExitStatus = 0 source = "runtime/collections/AbstractMutableCollection.kt" diff --git a/backend.native/tests/codegen/coroutines/suspendConversion.kt b/backend.native/tests/codegen/coroutines/suspendConversion.kt new file mode 100644 index 00000000000..12c66352e7e --- /dev/null +++ b/backend.native/tests/codegen/coroutines/suspendConversion.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +import kotlin.test.* + +import kotlin.coroutines.* +import kotlin.coroutines.intrinsics.* + +open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { + companion object : EmptyContinuation() + override fun resumeWith(result: Result) { result.getOrThrow() } +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun main() { + var result = 0 + + val f: () -> Unit = { result = 42 } + builder(f) + + assertEquals(42, result) +} \ No newline at end of file