[K/JS] Reset exceptionState inside coroutines with a finally block ^KT-58685 Fixed
This commit is contained in:
+8
-2
@@ -27,6 +27,8 @@ import org.jetbrains.kotlin.ir.util.setDeclarationsParent
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
object FINALLY_EXPRESSION : IrStatementOriginImpl("FINALLY_EXPRESSION")
|
||||
|
||||
class FinallyBlocksLowering(val context: CommonBackendContext, private val throwableType: IrType): FileLoweringPass, IrElementTransformerVoidWithContext() {
|
||||
|
||||
private interface HighLevelJump {
|
||||
@@ -271,13 +273,17 @@ class FinallyBlocksLowering(val context: CommonBackendContext, private val throw
|
||||
+irReturnableBlock(symbol, type) {
|
||||
+value
|
||||
}
|
||||
+copy(finallyExpression)
|
||||
+irComposite(resultType = context.irBuiltIns.unitType, origin = FINALLY_EXPRESSION) {
|
||||
+copy(finallyExpression)
|
||||
}
|
||||
}
|
||||
else -> irBlock(value, null, type) {
|
||||
val tmp = createTmpVariable(irReturnableBlock(symbol, type) {
|
||||
+irReturn(symbol, value)
|
||||
})
|
||||
+copy(finallyExpression)
|
||||
+irComposite(resultType = context.irBuiltIns.unitType, origin = FINALLY_EXPRESSION) {
|
||||
+copy(finallyExpression)
|
||||
}
|
||||
+irGet(tmp)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower.coroutines
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.isPure
|
||||
import org.jetbrains.kotlin.backend.common.lower.FINALLY_EXPRESSION
|
||||
import org.jetbrains.kotlin.backend.common.peek
|
||||
import org.jetbrains.kotlin.backend.common.pop
|
||||
import org.jetbrains.kotlin.backend.common.push
|
||||
@@ -396,6 +397,13 @@ class StateMachineBuilder(
|
||||
private fun wrap(expression: IrExpression, variable: IrVariableSymbol) =
|
||||
JsIrBuilder.buildSetVariable(variable, expression, unit)
|
||||
|
||||
override fun visitComposite(expression: IrComposite) {
|
||||
if (expression.origin == FINALLY_EXPRESSION) {
|
||||
catchBlockStack.peek()?.let(::setupExceptionState)
|
||||
}
|
||||
super.visitComposite(expression)
|
||||
}
|
||||
|
||||
override fun visitWhen(expression: IrWhen) {
|
||||
|
||||
if (expression !in suspendableNodes) return addStatement(expression)
|
||||
@@ -709,7 +717,6 @@ class StateMachineBuilder(
|
||||
catchBlockStack.pop()
|
||||
|
||||
updateState(tryState.catchState)
|
||||
|
||||
setupExceptionState(enclosingCatch)
|
||||
|
||||
var rethrowNeeded = true
|
||||
|
||||
Reference in New Issue
Block a user