diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java index 00561c91e3e..0bd904bb068 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java @@ -37,6 +37,8 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import java.util.*; +import static org.jetbrains.kotlin.resolve.DescriptorUtils.isObject; + public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrategy.CodegenBased { private final ResolvedCall resolvedCall; private final FunctionDescriptor referencedFunction; @@ -146,6 +148,12 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat (referencedFunction.getExtensionReceiverParameter() != null ? 1 : 0) - (receiverType != null ? 1 : 0); + if (receivers < 0 && referencedFunction instanceof ConstructorDescriptor && isObject(referencedFunction.getContainingDeclaration().getContainingDeclaration())) { + //reference to object nested class + //TODO: seems problem should be fixed on frontend side (note that object instance are captured by generated class) + receivers = 0; + } + List parameters = CollectionsKt.drop(functionDescriptor.getValueParameters(), receivers); for (int i = 0; i < parameters.size(); i++) { ValueParameterDescriptor parameter = parameters.get(i); diff --git a/compiler/testData/codegen/boxAgainstJava/callableReference/kt16412.kt b/compiler/testData/codegen/boxAgainstJava/callableReference/kt16412.kt new file mode 100644 index 00000000000..f4f582caca9 --- /dev/null +++ b/compiler/testData/codegen/boxAgainstJava/callableReference/kt16412.kt @@ -0,0 +1,20 @@ +// FILE: MFunction.java + +public interface MFunction { + R invoke(T t); +} + +// FILE: 1.kt + + +object Foo { + class Requester(val dealToBeOffered: String) +} + +class Bar { + val foo = MFunction(Foo::Requester) +} + +fun box(): String { + return Bar().foo("OK").dealToBeOffered +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/callableReference/kt16411.kt b/compiler/testData/codegen/boxInline/callableReference/kt16411.kt new file mode 100644 index 00000000000..d9465d269b3 --- /dev/null +++ b/compiler/testData/codegen/boxInline/callableReference/kt16411.kt @@ -0,0 +1,17 @@ +// FILE: 1.kt + +inline fun startFlow( + flowConstructor: (String) -> R +): R { + return flowConstructor("OK") +} + +object Foo { + class Requester(val dealToBeOffered: String) +} + +// FILE: 2.kt + +fun box(): String { + return startFlow(Foo::Requester).dealToBeOffered +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java index 3caf88c0a71..24a71d97837 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxAgainstJavaCodegenTestGenerated.java @@ -152,6 +152,12 @@ public class BlackBoxAgainstJavaCodegenTestGenerated extends AbstractBlackBoxAga doTest(fileName); } + @TestMetadata("kt16412.kt") + public void testKt16412() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/callableReference/kt16412.kt"); + doTest(fileName); + } + @TestMetadata("publicFinalField.kt") public void testPublicFinalField() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxAgainstJava/callableReference/publicFinalField.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 269d9edca53..9fb3350f48f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -596,6 +596,12 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo doTest(fileName); } + @TestMetadata("kt16411.kt") + public void testKt16411() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/kt16411.kt"); + doTest(fileName); + } + @TestMetadata("propertyIntrinsic.kt") public void testPropertyIntrinsic() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/propertyIntrinsic.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index b4c5c1a77e5..2713856eb17 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -596,6 +596,12 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi doTest(fileName); } + @TestMetadata("kt16411.kt") + public void testKt16411() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/kt16411.kt"); + doTest(fileName); + } + @TestMetadata("propertyIntrinsic.kt") public void testPropertyIntrinsic() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/propertyIntrinsic.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java index 93d2a14d0a2..619b2035a61 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/CallableReferenceInlineTestsGenerated.java @@ -66,6 +66,12 @@ public class CallableReferenceInlineTestsGenerated extends AbstractCallableRefer doTest(fileName); } + @TestMetadata("kt16411.kt") + public void testKt16411() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/kt16411.kt"); + doTest(fileName); + } + @TestMetadata("propertyIntrinsic.kt") public void testPropertyIntrinsic() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/callableReference/propertyIntrinsic.kt");