[JS IR BE] Fix reusing expression instances
This commit is contained in:
+7
-4
@@ -79,14 +79,17 @@ class MultipleCatchesLowering(val context: JsIrBackendContext) : FileLoweringPas
|
||||
val type = catch.catchParameter.type
|
||||
|
||||
val typeSymbol = type.classifierOrNull
|
||||
val castedPendingException = if (type !is IrDynamicType)
|
||||
buildImplicitCast(pendingException, type, typeSymbol!!)
|
||||
else pendingException
|
||||
val castedPendingException = {
|
||||
if (type !is IrDynamicType)
|
||||
buildImplicitCast(pendingException, type, typeSymbol!!)
|
||||
else
|
||||
pendingException
|
||||
}
|
||||
|
||||
val catchBody = catch.result.transform(object : IrElementTransformer<IrValueSymbol> {
|
||||
override fun visitGetValue(expression: IrGetValue, data: IrValueSymbol) =
|
||||
if (expression.symbol == data)
|
||||
castedPendingException
|
||||
castedPendingException()
|
||||
else
|
||||
expression
|
||||
}, catch.catchParameter.symbol)
|
||||
|
||||
+13
-8
@@ -22,7 +22,11 @@ import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.IrDynamicType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.isNothing
|
||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
||||
import org.jetbrains.kotlin.ir.visitors.*
|
||||
|
||||
class SuspendState(type: IrType) {
|
||||
@@ -62,7 +66,7 @@ class StateMachineBuilder(
|
||||
private val exceptionSymbol: IrProperty,
|
||||
private val exStateSymbol: IrProperty,
|
||||
private val stateSymbol: IrProperty,
|
||||
thisSymbol: IrValueParameterSymbol,
|
||||
private val thisSymbol: IrValueParameterSymbol,
|
||||
private val suspendResult: IrVariableSymbol
|
||||
) : IrElementVisitorVoid {
|
||||
|
||||
@@ -73,7 +77,7 @@ class StateMachineBuilder(
|
||||
private val booleanNotSymbol = context.irBuiltIns.booleanNotSymbol
|
||||
private val eqeqeqSymbol = context.irBuiltIns.eqeqeqSymbol
|
||||
|
||||
private val thisReceiver = JsIrBuilder.buildGetValue(thisSymbol)
|
||||
private val thisReceiver get() = JsIrBuilder.buildGetValue(thisSymbol)
|
||||
|
||||
private var hasExceptions = false
|
||||
|
||||
@@ -454,7 +458,9 @@ class StateMachineBuilder(
|
||||
irVar.apply { initializer = it }
|
||||
}
|
||||
JsIrBuilder.buildGetValue(irVar.symbol)
|
||||
} else arg
|
||||
} else {
|
||||
arg?.deepCopyWithSymbols(function.owner)
|
||||
}
|
||||
}
|
||||
|
||||
return newArguments
|
||||
@@ -606,13 +612,12 @@ class StateMachineBuilder(
|
||||
setupExceptionState(enclosingCatch)
|
||||
}
|
||||
|
||||
val ex = pendingException()
|
||||
|
||||
var rethrowNeeded = true
|
||||
|
||||
for (catch in aTry.catches) {
|
||||
val type = catch.catchParameter.type
|
||||
val initializer = if (type !is IrDynamicType) implicitCast(ex, type) else ex
|
||||
val initializer = if (type !is IrDynamicType) implicitCast(pendingException(), type) else pendingException()
|
||||
val irVar = catch.catchParameter.also {
|
||||
it.initializer = initializer
|
||||
}
|
||||
@@ -631,7 +636,7 @@ class StateMachineBuilder(
|
||||
maybeDoDispatch(exitDispatch)
|
||||
|
||||
} else {
|
||||
val check = buildIsCheck(ex, type)
|
||||
val check = buildIsCheck(pendingException(), type)
|
||||
|
||||
val branchBlock = JsIrBuilder.buildComposite(catchResult.type)
|
||||
|
||||
@@ -654,7 +659,7 @@ class StateMachineBuilder(
|
||||
|
||||
if (rethrowNeeded) {
|
||||
addExceptionEdge()
|
||||
addStatement(JsIrBuilder.buildThrow(nothing, ex))
|
||||
addStatement(JsIrBuilder.buildThrow(nothing, pendingException()))
|
||||
}
|
||||
|
||||
if (tryState.finallyState == null) {
|
||||
|
||||
Reference in New Issue
Block a user