Generate inline function arguments with parameters types

#KT-44429 Fixed
This commit is contained in:
Mikhael Bogdanov
2021-01-20 07:01:19 +01:00
parent 50ab9ed054
commit 147d60523d
13 changed files with 68 additions and 5 deletions
@@ -198,13 +198,13 @@ class ExpressionCodegen(
return StackValue.onStack(type, irType.toIrBasedKotlinType())
}
internal fun genOrGetLocal(expression: IrExpression, data: BlockInfo): StackValue {
internal fun genOrGetLocal(expression: IrExpression, type: Type, parameterType: IrType, 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 genOrGetLocal(expression.argument, type, parameterType, data)
}
}
}
@@ -212,7 +212,7 @@ class ExpressionCodegen(
return if (expression is IrGetValue)
StackValue.local(findLocalIndex(expression.symbol), frameMap.typeOf(expression.symbol), expression.type.toIrBasedKotlinType())
else
gen(expression, typeMapper.mapType(expression.type), expression.type, data)
gen(expression, type, parameterType, data)
}
fun generate() {
@@ -110,7 +110,7 @@ class IrInlineCodegen(
// Reuse an existing local if possible. NOTE: when stopping at a breakpoint placed
// in an inline function, arguments which reuse an existing local will not be visible
// in the debugger.
-> codegen.genOrGetLocal(argumentExpression, blockInfo)
-> codegen.genOrGetLocal(argumentExpression, parameterType, irValueParameter.type, blockInfo)
else
// Do not reuse locals for receivers. While it's actually completely fine, the non-IR
// backend does not do it for internal reasons, and here we replicate the debugging
@@ -128,7 +128,7 @@ class IrInlineCodegen(
}
private fun putCapturedValueOnStack(argumentExpression: IrExpression, valueType: Type, capturedParamIndex: Int) {
val onStack = codegen.genOrGetLocal(argumentExpression, BlockInfo())
val onStack = codegen.genOrGetLocal(argumentExpression, valueType, argumentExpression.type, BlockInfo())
val expectedType = JvmKotlinType(valueType, argumentExpression.type.toIrBasedKotlinType())
putArgumentOrCapturedToLocalVal(expectedType, onStack, capturedParamIndex, capturedParamIndex, ValueKind.CAPTURED)
}