From 51927836693cf8421b947de5d8dad023da8243a1 Mon Sep 17 00:00:00 2001 From: Svyatoslav Kuzmich Date: Thu, 23 Aug 2018 19:56:49 +0300 Subject: [PATCH] [JS IR BE] Workaround empty blocks in state machine builder --- .../backend/js/lower/coroutines/StateMachineBuilder.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/StateMachineBuilder.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/StateMachineBuilder.kt index d233a8c4778..202dc9ec3d2 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/StateMachineBuilder.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/coroutines/StateMachineBuilder.kt @@ -372,7 +372,9 @@ class StateMachineBuilder( currentBlock = branchBlock branch.result.acceptVoid(this) - if (currentBlock.statements.last() !is IrContinue) { + // TODO: block should not be empty + val lastStatement = currentBlock.statements.lastOrNull() + if (lastStatement != null && lastStatement !is IrContinue) { if (currentState !== rootState) { doDispatch(exitState) } @@ -382,7 +384,10 @@ class StateMachineBuilder( currentBlock = elseBlock } else { branch.result.acceptVoid(this) - if (currentBlock.statements.last() !is IrContinue) { + + // TODO: block should not be empty + val lastStatement = currentBlock.statements.lastOrNull() + if (lastStatement != null && lastStatement !is IrContinue) { if (currentState !== rootState) { doDispatch(exitState) }