diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java index 8303986acb3..94e66bde8ed 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ImplementationBodyCodegen.java @@ -49,10 +49,7 @@ import org.jetbrains.kotlin.resolve.BindingContext; import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilKt; -import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument; -import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument; -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; -import org.jetbrains.kotlin.resolve.calls.model.VarargValueArgument; +import org.jetbrains.kotlin.resolve.calls.model.*; import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt; @@ -1220,8 +1217,10 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { else if (descriptor instanceof CallableMemberDescriptor) { ResolvedCall call = CallUtilKt.getResolvedCall(expr, bindingContext); if (call != null) { - lookupReceiver(call.getDispatchReceiver()); - lookupReceiver(call.getExtensionReceiver()); + lookupReceivers(call); + } + if (call instanceof VariableAsFunctionResolvedCall) { + lookupReceivers(((VariableAsFunctionResolvedCall) call).getVariableCall()); } } else if (descriptor instanceof VariableDescriptor) { @@ -1234,6 +1233,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } } + private void lookupReceivers(@NotNull ResolvedCall call) { + lookupReceiver(call.getDispatchReceiver()); + lookupReceiver(call.getExtensionReceiver()); + } + private void lookupReceiver(@Nullable ReceiverValue value) { if (value instanceof ImplicitReceiver) { if (value instanceof ExtensionReceiver) { diff --git a/compiler/testData/codegen/box/operatorConventions/kt14201.kt b/compiler/testData/codegen/box/operatorConventions/kt14201.kt new file mode 100644 index 00000000000..3ee91af468f --- /dev/null +++ b/compiler/testData/codegen/box/operatorConventions/kt14201.kt @@ -0,0 +1,15 @@ +interface Intf { + val aValue: String +} + +class ClassB { + val x = { "OK" } + + val value: Intf = object : Intf { + override val aValue = x() + } +} + +fun box() : String { + return ClassB().value.aValue +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/operatorConventions/kt14201_2.kt b/compiler/testData/codegen/box/operatorConventions/kt14201_2.kt new file mode 100644 index 00000000000..b95b82d9172 --- /dev/null +++ b/compiler/testData/codegen/box/operatorConventions/kt14201_2.kt @@ -0,0 +1,27 @@ +class A { + val z: String = "OK" +} + +class B { + operator fun A.invoke(): String = z +} + +class ClassB { + val x = A() + + fun B.test(): String { + val value = object { + val z = x() + } + return value.z + } + + fun call(): String { + return B().test() + } + +} + +fun box(): String { + return ClassB().call() +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 859beec20cb..eea7645e8f7 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -10006,6 +10006,18 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt14201.kt") + public void testKt14201() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201.kt"); + doTest(fileName); + } + + @TestMetadata("kt14201_2.kt") + public void testKt14201_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201_2.kt"); + doTest(fileName); + } + @TestMetadata("kt4152.kt") public void testKt4152() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt4152.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index a8b3e0a685b..e8eaa90bebd 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -10006,6 +10006,18 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt14201.kt") + public void testKt14201() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201.kt"); + doTest(fileName); + } + + @TestMetadata("kt14201_2.kt") + public void testKt14201_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt14201_2.kt"); + doTest(fileName); + } + @TestMetadata("kt4152.kt") public void testKt4152() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/operatorConventions/kt4152.kt");