[IR] Make IrReturnTargetSymbol a sealed interface
This commit is contained in:
committed by
Space Team
parent
6c211f3a39
commit
93d1932ccb
-1
@@ -149,7 +149,6 @@ class AutoboxingTransformer(context: JsCommonBackendContext) : AbstractValueUsag
|
||||
is IrSimpleFunctionSymbol -> useReturnableExpressionAsType(returnTarget.owner.returnType)
|
||||
is IrConstructorSymbol -> useReturnableExpressionAsType(irBuiltIns.unitType)
|
||||
is IrReturnableBlockSymbol -> useReturnableExpressionAsType(returnTarget.owner.type)
|
||||
else -> error(returnTarget)
|
||||
}
|
||||
|
||||
override fun IrExpression.useExpressionAsType(actualType: IrType, expectedType: IrType): IrExpression {
|
||||
|
||||
+12
-9
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||
import org.jetbrains.kotlin.ir.types.isAny
|
||||
import org.jetbrains.kotlin.ir.util.constructedClassType
|
||||
@@ -125,17 +126,19 @@ class IrElementToJsStatementTransformer : BaseIrElementToJsNodeTransformer<JsSta
|
||||
}
|
||||
|
||||
override fun visitReturn(expression: IrReturn, context: JsGenerationContext): JsStatement {
|
||||
val targetSymbol = expression.returnTargetSymbol
|
||||
val lastStatementTransformer: (() -> JsExpression) -> JsStatement =
|
||||
if (targetSymbol is IrReturnableBlockSymbol) {
|
||||
// TODO assert that value is Unit?
|
||||
{
|
||||
context.getNameForReturnableBlock(targetSymbol.owner)
|
||||
.takeIf { !expression.isTheLastReturnStatementIn(targetSymbol) }
|
||||
?.run { JsBreak(makeRef()) } ?: JsEmpty
|
||||
when (val targetSymbol = expression.returnTargetSymbol) {
|
||||
is IrReturnableBlockSymbol -> {
|
||||
// TODO assert that value is Unit?
|
||||
{
|
||||
context.getNameForReturnableBlock(targetSymbol.owner)
|
||||
.takeIf { !expression.isTheLastReturnStatementIn(targetSymbol) }
|
||||
?.run { JsBreak(makeRef()) } ?: JsEmpty
|
||||
}
|
||||
}
|
||||
is IrFunctionSymbol -> {
|
||||
{ JsReturn(it()) }
|
||||
}
|
||||
} else {
|
||||
{ JsReturn(it()) }
|
||||
}
|
||||
|
||||
return expression.value.maybeOptimizeIntoSwitch(context, lastStatementTransformer).withSource(expression, context)
|
||||
|
||||
Reference in New Issue
Block a user