[IR] Extracted implicitCastIfNeeded to common utils

This commit is contained in:
Igor Chevdar
2023-02-09 13:22:05 +02:00
committed by Space Team
parent 750bb5c8c4
commit 5e6aa649ed
2 changed files with 6 additions and 7 deletions
@@ -407,13 +407,6 @@ class FunctionInlining(
override fun visitElement(element: IrElement) = element.accept(this, null)
}
private fun IrExpression.implicitCastIfNeededTo(type: IrType) =
// No need to cast expressions of type nothing
if (type == this.type || (insertAdditionalImplicitCasts && this.type == context.irBuiltIns.nothingType))
this
else
IrTypeOperatorCallImpl(startOffset, endOffset, type, IrTypeOperator.IMPLICIT_CAST, type, this)
// With `insertAdditionalImplicitCasts` flag we sometimes insert
// casts to inline lambda parameters before calling `invoke` on them.
// Unwrapping these casts helps us satisfy inline lambda call detection logic.
@@ -183,6 +183,12 @@ fun IrExpression.coerceToUnitIfNeeded(valueType: IrType, irBuiltIns: IrBuiltIns,
)
}
fun IrExpression.implicitCastIfNeededTo(type: IrType) =
if (type == this.type || this.type.isNothing())
this
else
IrTypeOperatorCallImpl(startOffset, endOffset, type, IrTypeOperator.IMPLICIT_CAST, type, this)
fun IrFunctionAccessExpression.usesDefaultArguments(): Boolean =
symbol.owner.valueParameters.any { this.getValueArgument(it.index) == null }