diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index d1c3fa3a81139..d55c344ae981c 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -22346,6 +22346,12 @@ public void testKt46408() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt46408.kt"); } + @Test + @TestMetadata("kt49613.kt") + public void testKt49613() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt49613.kt"); + } + @Test @TestMetadata("localFunction1.kt") public void testLocalFunction1() throws Exception { diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt index 2d6a1a67eaecb..d186fbd6b18cc 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt @@ -270,7 +270,7 @@ private class TypeOperatorLowering(private val context: JvmBackendContext) : Fil targetRef: IrFunctionReference ): IrCall { fun fail(message: String): Nothing = - throw AssertionError("$message, irFunRef:\n${targetRef.dump()}") + throw AssertionError("$message, targetRef:\n${targetRef.dump()}") val dynamicCallArguments = ArrayList() diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt index b395b2f5b35fe..358a0e467c010 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/indy/LambdaMetafactoryArguments.kt @@ -91,9 +91,8 @@ internal class LambdaMetafactoryArgumentsBuilder( if (implFun.isInline) return null - if (implFun is IrConstructor && DescriptorVisibilities.isPrivate(implFun.visibility)) { + if (isConstructorRequiringAccessor(implFun)) { // Kotlin generates constructor accessors differently from Java. - // TODO more precise accessibility check (see SyntheticAccessorLowering::isAccessible) return null } @@ -138,6 +137,15 @@ internal class LambdaMetafactoryArgumentsBuilder( return getLambdaMetafactoryArgsOrNullInner(reference, samMethod, samType, implFun) } + private fun isConstructorRequiringAccessor(implFun: IrFunction): Boolean { + if (implFun !is IrConstructor) return false + // We don't do exact accessibility check here: + // constructor will be called by a class generated by LambdaMetafactory at runtime. + val visibility = implFun.visibility + return visibility == DescriptorVisibilities.PROTECTED || + DescriptorVisibilities.isPrivate(visibility) + } + private val javaIoSerializableFqn = FqName("java.io").child(Name.identifier("Serializable")) diff --git a/compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt49613.kt b/compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt49613.kt new file mode 100644 index 0000000000000..7a207e0eb94d7 --- /dev/null +++ b/compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt49613.kt @@ -0,0 +1,28 @@ +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// SAM_CONVERSIONS: INDY +// FILE: kt49613.kt + +interface GetStep { + fun get(): Any +} + +class Outer protected constructor(val ok: Any) { + constructor(): this("xxx") + + val obj = object : GetStep { + override fun get() = Step(::Outer) + } +} + +fun box(): String { + val s = Outer().obj.get() as Step + val t = s.step("OK") as Outer + return t.ok as String +} + +// FILE: Step.java + +public interface Step { + Object step(String string); +} \ No newline at end of file diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index c1d056cc82cfd..299e06b9c83a3 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -22214,6 +22214,12 @@ public void testKt46408() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt46408.kt"); } + @Test + @TestMetadata("kt49613.kt") + public void testKt49613() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt49613.kt"); + } + @Test @TestMetadata("localFunction1.kt") public void testLocalFunction1() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 585a5f64b4841..2e110981f6614 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -22346,6 +22346,12 @@ public void testKt46408() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt46408.kt"); } + @Test + @TestMetadata("kt49613.kt") + public void testKt49613() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt49613.kt"); + } + @Test @TestMetadata("localFunction1.kt") public void testLocalFunction1() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 14e966fb2a66f..2fc4223209214 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -18589,6 +18589,11 @@ public void testKt46408() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt46408.kt"); } + @TestMetadata("kt49613.kt") + public void testKt49613() throws Exception { + runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/kt49613.kt"); + } + @TestMetadata("localFunction1.kt") public void testLocalFunction1() throws Exception { runTest("compiler/testData/codegen/box/invokedynamic/sam/functionRefToJavaInterface/localFunction1.kt");