[Native] Always cast expression to the expected type after inline
Right now, during the process of inlining, the compiler erases types. Because of that, we can end up with some random type (for example, `Any`) where the concrete type was expected (for example, `Int`). Compiler must insert a cast in the required places. #KT-66017 Fixed
This commit is contained in:
+15
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.ir.types.isUnit
|
||||
import org.jetbrains.kotlin.ir.util.isSuspend
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
|
||||
data class TailSuspendCalls(val callSites: Set<IrCall>, val hasNotTailSuspendCalls: Boolean)
|
||||
|
||||
@@ -36,6 +37,14 @@ fun collectTailSuspendCalls(context: CommonBackendContext, irFunction: IrSimpleF
|
||||
element.acceptChildren(this, VisitorState(data.insideTryBlock, isTailExpression = false))
|
||||
}
|
||||
|
||||
override fun visitTypeOperator(expression: IrTypeOperatorCall, data: VisitorState) {
|
||||
if (expression.operator == IrTypeOperator.IMPLICIT_CAST) {
|
||||
expression.acceptChildren(this, data)
|
||||
} else {
|
||||
super.visitTypeOperator(expression, data)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTry(aTry: IrTry, data: VisitorState) {
|
||||
aTry.tryResult.accept(this, VisitorState(insideTryBlock = true, isTailExpression = false))
|
||||
aTry.catches.forEach { it.result.accept(this, data) }
|
||||
@@ -98,8 +107,12 @@ fun collectTailSuspendCalls(context: CommonBackendContext, irFunction: IrSimpleF
|
||||
expression.acceptChildren(this, VisitorState(data.insideTryBlock, isTailExpression))
|
||||
}
|
||||
|
||||
private fun IrExpression.isUnitRead(): Boolean =
|
||||
this is IrGetObjectValue && symbol == context.irBuiltIns.unitClass
|
||||
private fun IrExpression.isUnitRead(): Boolean {
|
||||
if (this is IrTypeOperatorCall) {
|
||||
return this.argument.isUnitRead()
|
||||
}
|
||||
return this is IrGetObjectValue && symbol == context.irBuiltIns.unitClass
|
||||
}
|
||||
|
||||
private fun IrCall.isReturnIfSuspendedCall() =
|
||||
symbol == context.ir.symbols.returnIfSuspended
|
||||
|
||||
Reference in New Issue
Block a user