diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/IrInterpreter.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/IrInterpreter.kt index 343cdd76911..86ac488828f 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/IrInterpreter.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/IrInterpreter.kt @@ -231,7 +231,7 @@ class IrInterpreter(val irBuiltIns: IrBuiltIns, private val bodyMap: Map ): ExecutionResult { // if irFunction is lambda and it has receiver, then first descriptor must be taken from extension receiver - val receiverAsFirstArgument = when (expression.dispatchReceiver?.type?.isFunction()) { + val receiverAsFirstArgument = when (expression.valueArgumentsCount != irFunction.valueParameters.size) { true -> listOfNotNull(irFunction.getExtensionReceiver()) else -> listOf() } @@ -861,7 +861,23 @@ class IrInterpreter(val irBuiltIns: IrBuiltIns, private val bodyMap: Map function.fields.add(Variable(it, receiver)) } } + function.irFunction.getExtensionReceiver()?.let { extensionReceiver?.let { receiver -> function.fields.add(Variable(it, receiver)) } } + + if (function.irFunction.isLocal) function.fields.addAll(stack.getAll()) // TODO save only necessary declarations + stack.pushReturnValue(function) return Next } diff --git a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/proxy/reflection/KProperty0Proxy.kt b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/proxy/reflection/KProperty0Proxy.kt index 7dc9a48a383..cbad7f65245 100644 --- a/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/proxy/reflection/KProperty0Proxy.kt +++ b/compiler/ir/ir.interpreter/src/org/jetbrains/kotlin/ir/interpreter/proxy/reflection/KProperty0Proxy.kt @@ -8,8 +8,8 @@ package org.jetbrains.kotlin.ir.interpreter.proxy.reflection import org.jetbrains.kotlin.ir.interpreter.IrInterpreter import org.jetbrains.kotlin.ir.interpreter.stack.Variable import org.jetbrains.kotlin.ir.interpreter.state.reflection.KPropertyState -import org.jetbrains.kotlin.ir.interpreter.state.State import org.jetbrains.kotlin.ir.interpreter.toState +import org.jetbrains.kotlin.ir.util.resolveFakeOverride import kotlin.reflect.* internal open class KProperty0Proxy( @@ -21,7 +21,8 @@ internal open class KProperty0Proxy( override fun call(vararg args: Any?): Any? { checkArguments(0, args.size) - return state.dispatchReceiver!!.getState(state.property.symbol)!! + val actualPropertySymbol = state.property.resolveFakeOverride()?.symbol ?: state.property.symbol + return state.dispatchReceiver!!.getState(actualPropertySymbol)!! } override fun callBy(args: Map): Any? {