From 9066614cb9d3a5dc5312966a62f64c9daa1e04a7 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 20 Nov 2019 08:38:19 +0100 Subject: [PATCH] Support inlining of implicitly casted lambda parameter --- .../backend/jvm/codegen/ExpressionCodegen.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt index c2d04443784..3edaebecefb 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/ExpressionCodegen.kt @@ -167,11 +167,22 @@ class ExpressionCodegen( return StackValue.onStack(type, irType.toKotlinType()) } - internal fun genOrGetLocal(expression: IrExpression, data: BlockInfo): StackValue = - if (expression is IrGetValue) + internal fun genOrGetLocal(expression: IrExpression, data: BlockInfo): StackValue { + if (irFunction.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) { + if (expression is IrTypeOperatorCall && expression.operator == IrTypeOperator.IMPLICIT_CAST) { + // inline lambda parameters are passed from `foo$default` to `foo` call with implicit cast, + // we need return pure StackValue.local value to be able proper inline this parameter later + if (expression.type.makeNullable() == expression.argument.type) { + return genOrGetLocal(expression.argument, data) + } + } + } + + return if (expression is IrGetValue) StackValue.local(findLocalIndex(expression.symbol), frameMap.typeOf(expression.symbol), expression.type.toKotlinType()) else gen(expression, typeMapper.mapType(expression.type), expression.type, data) + } fun generate() { mv.visitCode()