From 36a99da8209defc9c16fdeccbeabbf1f26966fe3 Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Thu, 5 Jul 2018 23:38:02 +0300 Subject: [PATCH] Break/finally chain in suspend function test fix & workaround --- .../box/coroutines/controlFlow/breakFinally.kt | 6 +++--- .../js/coroutine/CoroutineFunctionTransformer.kt | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/compiler/testData/codegen/box/coroutines/controlFlow/breakFinally.kt b/compiler/testData/codegen/box/coroutines/controlFlow/breakFinally.kt index 0239d8d4ae3..448a6601ac6 100644 --- a/compiler/testData/codegen/box/coroutines/controlFlow/breakFinally.kt +++ b/compiler/testData/codegen/box/coroutines/controlFlow/breakFinally.kt @@ -1,5 +1,5 @@ -// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS +// IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JVM_IR // WITH_RUNTIME // WITH_COROUTINES @@ -47,8 +47,8 @@ fun box(): String { result += "@" for (y in listOf("F", "G")) { try { - result += suspendWithResult(z) - if (z == "G") { + result += suspendWithResult(y) + if (y == "G") { break } } diff --git a/js/js.inliner/src/org/jetbrains/kotlin/js/coroutine/CoroutineFunctionTransformer.kt b/js/js.inliner/src/org/jetbrains/kotlin/js/coroutine/CoroutineFunctionTransformer.kt index 2b236d26a5a..b9bddd6845a 100644 --- a/js/js.inliner/src/org/jetbrains/kotlin/js/coroutine/CoroutineFunctionTransformer.kt +++ b/js/js.inliner/src/org/jetbrains/kotlin/js/coroutine/CoroutineFunctionTransformer.kt @@ -280,7 +280,18 @@ class CoroutineFunctionTransformer(private val function: JsFunction, name: Strin statements += block.statements } } - val switchStatement = JsSwitch(stateRef.deepCopy(), cases) + + // NOTE: temporary workaround to let tests run without hanging + // TODO: probably default statement should be removed asap the issue about nested break & finally is fixed + val defaultCase = JsDefault().apply { + val block = JsBlock( + assignment(stateRef, JsIntLiteral(indexOfGlobalCatch)).makeStmt(), + JsThrow(JsNew(JsNameRef("Error"), listOf(JsStringLiteral("State Machine Unreachable execution")))) + ) + statements += block + } + + val switchStatement = JsSwitch(stateRef.deepCopy(), cases + defaultCase) val loop = JsDoWhile(JsBooleanLiteral(true), JsTry(JsBlock(switchStatement), catch, null)) return listOf(loop)