diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt index 762e32ebc40..8f96b4ec4e6 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/FunctionInlining.kt @@ -14,7 +14,6 @@ import org.jetbrains.kotlin.backend.konan.Context import org.jetbrains.kotlin.backend.konan.descriptors.resolveFakeOverride import org.jetbrains.kotlin.backend.konan.ir.* import org.jetbrains.kotlin.config.languageVersionSettings -import org.jetbrains.kotlin.descriptors.ValueDescriptor import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.builders.irGet @@ -23,12 +22,10 @@ import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol -import org.jetbrains.kotlin.ir.symbols.IrValueSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrReturnableBlockSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid -import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.util.OperatorNameConventions @@ -238,9 +235,9 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid val immediateCall = with(expression) { if (function is IrConstructor) - IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, type, function.symbol) + IrConstructorCallImpl.fromSymbolOwner(startOffset, endOffset, function.returnType, function.symbol) else - IrCallImpl(startOffset, endOffset, type, functionArgument.symbol) + IrCallImpl(startOffset, endOffset, function.returnType, functionArgument.symbol) }.apply { functionParameters.forEach { val argument = @@ -249,15 +246,19 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid else valueParameters[unboundIndex++].second when (it) { - function.dispatchReceiverParameter -> this.dispatchReceiver = argument - function.extensionReceiverParameter -> this.extensionReceiver = argument - else -> putValueArgument(it.index, argument) + function.dispatchReceiverParameter -> + this.dispatchReceiver = argument.implicitCastIfNeededTo(function.dispatchReceiverParameter!!.type) + + function.extensionReceiverParameter -> + this.extensionReceiver = argument.implicitCastIfNeededTo(function.extensionReceiverParameter!!.type) + + else -> putValueArgument(it.index, argument.implicitCastIfNeededTo(function.valueParameters[it.index].type)) } } assert(unboundIndex == valueParameters.size) { "Not all arguments of are used" } for (index in 0 until functionArgument.typeArgumentsCount) putTypeArgument(index, functionArgument.getTypeArgument(index)) - } + }.implicitCastIfNeededTo(expression.type) return this@FunctionInlining.visitExpression(super.visitExpression(immediateCall)) } if (functionArgument !is IrBlock) @@ -273,6 +274,12 @@ internal class FunctionInlining(val context: Context) : IrElementTransformerVoid override fun visitElement(element: IrElement) = element.accept(this, null) } + private fun IrExpression.implicitCastIfNeededTo(type: IrType) = + if (type == this.type) + this + else + IrTypeOperatorCallImpl(startOffset, endOffset, type, IrTypeOperator.IMPLICIT_CAST, type, this) + private fun isLambdaCall(irCall: IrCall): Boolean { val callee = irCall.symbol.owner val dispatchReceiver = callee.dispatchReceiverParameter ?: return false diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt index 46616b2f434..dc9c6abe01a 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/PostInlineLowering.kt @@ -100,9 +100,9 @@ internal class PostInlineLowering(val context: Context) : FileLoweringPass { // Basic Multilingual Plane, so we could just append data "as is". builder.append(value.toChar()) } - expression.putValueArgument(0, IrConstImpl( + expression.putValueArgument(0, IrConstImpl( expression.startOffset, expression.endOffset, - context.ir.symbols.immutableBlob.typeWithoutArguments, + context.irBuiltIns.stringType, IrConstKind.String, builder.toString())) } else if (expression.symbol.owner.isTypeOfIntrinsic()) { val type = expression.getTypeArgument(0)