JVM_IR: use substituted return type when lowering inline references
#KT-48267 Fixed
This commit is contained in:
+5
-3
@@ -128,14 +128,16 @@ private class InlineCallableReferenceToLambdaTransformer(
|
|||||||
val irBuilder = context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset)
|
val irBuilder = context.createJvmIrBuilder(currentScope!!.scope.scopeOwnerSymbol, expression.startOffset, expression.endOffset)
|
||||||
return irBuilder.irBlock(expression, IrStatementOrigin.LAMBDA) {
|
return irBuilder.irBlock(expression, IrStatementOrigin.LAMBDA) {
|
||||||
val (receiverParameter, receiverValue) = expression.getArgumentsWithIr().singleOrNull() ?: (null to null)
|
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 {
|
val function = context.irFactory.buildFun {
|
||||||
setSourceRange(expression)
|
setSourceRange(expression)
|
||||||
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
|
origin = IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA
|
||||||
name = Name.identifier(STUB_FOR_INLINING)
|
name = Name.identifier(STUB_FOR_INLINING)
|
||||||
visibility = DescriptorVisibilities.LOCAL
|
visibility = DescriptorVisibilities.LOCAL
|
||||||
returnType = referencedFunction.returnType
|
returnType = resultType
|
||||||
isSuspend = referencedFunction.isSuspend
|
isSuspend = referencedFunction.isSuspend
|
||||||
}.apply {
|
}.apply {
|
||||||
parent = currentDeclarationParent!!
|
parent = currentDeclarationParent!!
|
||||||
@@ -154,7 +156,7 @@ private class InlineCallableReferenceToLambdaTransformer(
|
|||||||
expression.startOffset,
|
expression.startOffset,
|
||||||
expression.endOffset
|
expression.endOffset
|
||||||
).run {
|
).run {
|
||||||
irExprBody(irCall(referencedFunction).apply {
|
irExprBody(irCall(referencedFunction.symbol, resultType).apply {
|
||||||
symbol.owner.allTypeParameters.forEach {
|
symbol.owner.allTypeParameters.forEach {
|
||||||
putTypeArgument(it.index, expression.getTypeArgument(it.index))
|
putTypeArgument(it.index, expression.getTypeArgument(it.index))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
|
|
||||||
fun g(b: (Int, (Int) -> String) -> Array<String>): Array<String> =
|
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]
|
||||||
|
|||||||
Reference in New Issue
Block a user