diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 4f1841c0d28..eba440c31d6 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -821,32 +821,41 @@ task coroutines_controlFlow_if2(type: RunKonanTest) { source = "codegen/coroutines/controlFlow_if2.kt" } -// Enable after finally blocks lowering. - task coroutines_controlFlow_finally1(type: RunKonanTest) { - disabled = true goldValue = "f1\ns1\n117\n" source = "codegen/coroutines/controlFlow_finally1.kt" } task coroutines_controlFlow_finally2(type: RunKonanTest) { - disabled = true goldValue = "f1\ns1\n117\n" source = "codegen/coroutines/controlFlow_finally2.kt" } task coroutines_controlFlow_finally3(type: RunKonanTest) { - disabled = true goldValue = "f1\ns1\n117\n" source = "codegen/coroutines/controlFlow_finally3.kt" } task coroutines_controlFlow_finally4(type: RunKonanTest) { - disabled = true - goldValue = "s1\nfinally\n117\n" + goldValue = "s1\nfinally\n42\n" source = "codegen/coroutines/controlFlow_finally4.kt" } +task coroutines_controlFlow_finally5(type: RunKonanTest) { + goldValue = "s1\nf2\nfinally\n1\n" + source = "codegen/coroutines/controlFlow_finally5.kt" +} + +task coroutines_controlFlow_finally6(type: RunKonanTest) { + goldValue = "s1\nfinally\nerror\n0\n" + source = "codegen/coroutines/controlFlow_finally6.kt" +} + +task coroutines_controlFlow_finally7(type: RunKonanTest) { + goldValue = "s1\nf2\nfinally1\ns2\nfinally2\n42\n" + source = "codegen/coroutines/controlFlow_finally7.kt" +} + task coroutines_controlFlow_inline1(type: RunKonanTest) { goldValue = "42\n" source = "codegen/coroutines/controlFlow_inline1.kt" diff --git a/backend.native/tests/codegen/coroutines/controlFlow_finally5.kt b/backend.native/tests/codegen/coroutines/controlFlow_finally5.kt new file mode 100644 index 00000000000..7959629e369 --- /dev/null +++ b/backend.native/tests/codegen/coroutines/controlFlow_finally5.kt @@ -0,0 +1,49 @@ +import kotlin.coroutines.experimental.* +import kotlin.coroutines.experimental.intrinsics.* + +open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { + companion object : EmptyContinuation() + override fun resume(value: Any?) {} + override fun resumeWithException(exception: Throwable) { throw exception } +} + +suspend fun s1(): Int = suspendCoroutineOrReturn { x -> + println("s1") + x.resumeWithException(Error()) + COROUTINE_SUSPENDED +} + +fun f1(): Int { + println("f1") + return 117 +} + +fun f2(): Int { + println("f2") + return 1 +} + +fun f3(x: Int, y: Int): Int { + println("f3") + return x + y +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun main(args: Array) { + var result = 0 + + builder { + try { + result = s1() + } catch (t: Throwable) { + result = f2() + } finally { + println("finally") + } + } + + println(result) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/coroutines/controlFlow_finally6.kt b/backend.native/tests/codegen/coroutines/controlFlow_finally6.kt new file mode 100644 index 00000000000..126e5975eb7 --- /dev/null +++ b/backend.native/tests/codegen/coroutines/controlFlow_finally6.kt @@ -0,0 +1,54 @@ +import kotlin.coroutines.experimental.* +import kotlin.coroutines.experimental.intrinsics.* + +open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { + companion object : EmptyContinuation() + override fun resume(value: Any?) {} + override fun resumeWithException(exception: Throwable) { throw exception } +} + +suspend fun s1(): Int = suspendCoroutineOrReturn { x -> + println("s1") + x.resumeWithException(Error("error")) + COROUTINE_SUSPENDED +} + +fun f1(): Int { + println("f1") + return 117 +} + +fun f2(): Int { + println("f2") + return 1 +} + +fun f3(x: Int, y: Int): Int { + println("f3") + return x + y +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun main(args: Array) { + var result = 0 + + builder { + try { + try { + result = s1() + } catch (t: ClassCastException) { + result = f2() + } finally { + println("finally") + } + } + catch(t: Error) { + println(t.message) + } + } + + println(result) +} \ No newline at end of file diff --git a/backend.native/tests/codegen/coroutines/controlFlow_finally7.kt b/backend.native/tests/codegen/coroutines/controlFlow_finally7.kt new file mode 100644 index 00000000000..de4b9fcb137 --- /dev/null +++ b/backend.native/tests/codegen/coroutines/controlFlow_finally7.kt @@ -0,0 +1,60 @@ +import kotlin.coroutines.experimental.* +import kotlin.coroutines.experimental.intrinsics.* + +open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation { + companion object : EmptyContinuation() + override fun resume(value: Any?) {} + override fun resumeWithException(exception: Throwable) { throw exception } +} + +suspend fun s1(): Int = suspendCoroutineOrReturn { x -> + println("s1") + x.resumeWithException(Error()) + COROUTINE_SUSPENDED +} + +suspend fun s2(): Int = suspendCoroutineOrReturn { x -> + println("s2") + x.resume(42) + COROUTINE_SUSPENDED +} + +fun f1(): Int { + println("f1") + return 117 +} + +fun f2(): Int { + println("f2") + return 1 +} + +fun f3(x: Int, y: Int): Int { + println("f3") + return x + y +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun main(args: Array) { + var result = 0 + + builder { + try { + try { + result = s1() + } catch (t: Throwable) { + result = f2() + } finally { + println("finally1") + result = s2() + } + } finally { + println("finally2") + } + } + + println(result) +} \ No newline at end of file