diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt index 8b9623546a8..c28a19f9840 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InlineCallableReferenceToLambda.kt @@ -128,14 +128,16 @@ private class InlineCallableReferenceToLambdaTransformer( val irBuilder = context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset) return irBuilder.irBlock(expression, IrStatementOrigin.LAMBDA) { val (receiverParameter, receiverValue) = expression.getArgumentsWithIr().singleOrNull() ?: (null to null) - val argumentTypes = (expression.type as IrSimpleType).arguments.dropLast(1).map { (it as IrTypeProjection).type } + val kFunctionArguments = (expression.type as IrSimpleType).arguments.map { (it as IrTypeProjection).type } + val argumentTypes = kFunctionArguments.dropLast(1) + val resultType = kFunctionArguments.last() val function = context.irFactory.buildFun { setSourceRange(expression) origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA name = Name.identifier(STUB_FOR_INLINING) visibility = DescriptorVisibilities.LOCAL - returnType = referencedFunction.returnType + returnType = resultType isSuspend = referencedFunction.isSuspend }.apply { parent = currentDeclarationParent!! @@ -154,7 +156,7 @@ private class InlineCallableReferenceToLambdaTransformer( expression.startOffset, expression.endOffset ).run { - irExprBody(irCall(referencedFunction).apply { + irExprBody(irCall(referencedFunction.symbol, resultType).apply { symbol.owner.allTypeParameters.forEach { putTypeArgument(it.index, expression.getTypeArgument(it.index)) } diff --git a/compiler/testData/codegen/box/callableReference/arrayConstructor.kt b/compiler/testData/codegen/box/callableReference/arrayConstructor.kt index 56e124a8615..7370737da60 100644 --- a/compiler/testData/codegen/box/callableReference/arrayConstructor.kt +++ b/compiler/testData/codegen/box/callableReference/arrayConstructor.kt @@ -1,6 +1,9 @@ // WITH_RUNTIME fun g(b: (Int, (Int) -> String) -> Array): Array = - b(1) { "OK" } + b(1) { "O" } -fun box(): String = g(::Array)[0] +inline fun h(b: (Int, (Int) -> String) -> Array): Array = + b(1) { "K" } + +fun box(): String = g(::Array)[0] + h(::Array)[0]