JVM_IR: use substituted return type when lowering inline references

#KT-48267 Fixed
This commit is contained in:
pyos
2021-08-16 08:36:19 +02:00
committed by max-kammerer
parent 0b84de31b7
commit 858bd47c45
2 changed files with 10 additions and 5 deletions
@@ -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))
}
@@ -1,6 +1,9 @@
// WITH_RUNTIME
fun g(b: (Int, (Int) -> String) -> Array<String>): Array<String> =
b(1) { "OK" }
b(1) { "O" }
fun box(): String = g(::Array)[0]
inline fun h(b: (Int, (Int) -> String) -> Array<String>): Array<String> =
b(1) { "K" }
fun box(): String = g(::Array)[0] + h(::Array)[0]