From ba8147cd47a79e4a407a21e7970e040346336b7f Mon Sep 17 00:00:00 2001 From: Ivan Kylchik Date: Thu, 7 May 2020 15:10:29 +0300 Subject: [PATCH] Allow lambda to be used in built in calculation Primary use case to allow lambda null check --- .../kotlin/backend/common/interpreter/IrInterpreter.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/IrInterpreter.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/IrInterpreter.kt index d2ab16c0f25..9b668d03563 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/IrInterpreter.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/interpreter/IrInterpreter.kt @@ -215,9 +215,16 @@ class IrInterpreter(irModule: IrModuleFragment) { val receiverType = descriptor.dispatchReceiverParameter?.type ?: descriptor.extensionReceiverParameter?.type val argsType = listOfNotNull(receiverType) + descriptor.valueParameters.map { it.original.type } - val argsValues = args.map { (it as? Complex)?.getOriginal() ?: (it as Primitive<*>).value } + val argsValues = args.map { + when (it) { + is Complex -> it.getOriginal() + is Primitive<*> -> it.value + else -> it // lambda can be used in built in calculation, for example, in null check + } + } val signature = CompileTimeFunction(methodName, argsType.map { it.toString() }) + // TODO replace unary, binary, ternary functions with vararg val result = when (argsType.size) { 1 -> { val function = unaryFunctions[signature]