[JS IR BE] Materialize Unit object during upcasts in AutoBoxingTransformer
This commit is contained in:
+22
@@ -26,6 +26,20 @@ class AutoboxingTransformer(val context: JsIrBackendContext) : AbstractValueUsag
|
|||||||
irFile.patchDeclarationParents()
|
irFile.patchDeclarationParents()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private tailrec fun IrExpression.isGetUnit(): Boolean =
|
||||||
|
when(this) {
|
||||||
|
is IrContainerExpression ->
|
||||||
|
when (val lastStmt = this.statements.lastOrNull()) {
|
||||||
|
is IrExpression -> lastStmt.isGetUnit()
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
is IrGetObjectValue ->
|
||||||
|
this.symbol == irBuiltIns.unitClass
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
override fun IrExpression.useAs(type: IrType): IrExpression {
|
override fun IrExpression.useAs(type: IrType): IrExpression {
|
||||||
|
|
||||||
val actualType = when (this) {
|
val actualType = when (this) {
|
||||||
@@ -68,6 +82,14 @@ class AutoboxingTransformer(val context: JsIrBackendContext) : AbstractValueUsag
|
|||||||
|
|
||||||
val expectedType = type
|
val expectedType = type
|
||||||
|
|
||||||
|
if (actualType.isUnit() && !expectedType.isUnit()) {
|
||||||
|
// Don't materialize Unit if value is known to be proper Unit on runtime
|
||||||
|
if (!this.isGetUnit()) {
|
||||||
|
val unitValue = JsIrBuilder.buildGetObjectValue(actualType, context.symbolTable.referenceClass(context.builtIns.unit))
|
||||||
|
return JsIrBuilder.buildComposite(actualType, listOf(this, unitValue))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val actualInlinedClass = actualType.getInlinedClass()
|
val actualInlinedClass = actualType.getInlinedClass()
|
||||||
val expectedInlinedClass = expectedType.getInlinedClass()
|
val expectedInlinedClass = expectedType.getInlinedClass()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user