JVM KT-49613 use adapter for indy reference to protected constructor

This commit is contained in:
Dmitry Petrov
2021-11-10 16:03:34 +03:00
committed by TeamCityServer
parent 76bdf4ff1a
commit 916379c0e7
7 changed files with 62 additions and 3 deletions
@@ -22666,6 +22666,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
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 {
@@ -553,7 +553,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<IrExpression>()
@@ -145,9 +145,8 @@ internal class LambdaMetafactoryArgumentsBuilder(
functionHazard = true
}
if (implFun is IrConstructor && DescriptorVisibilities.isPrivate(implFun.visibility)) {
if (isConstructorRequiringAccessor(implFun)) {
// Kotlin generates constructor accessors differently from Java.
// We don't do exact accessibility check here, just
functionHazard = true
}
@@ -214,6 +213,15 @@ internal class LambdaMetafactoryArgumentsBuilder(
?: MetafactoryArgumentsResult.Failure.FunctionHazard
}
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"))
@@ -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);
}
@@ -22504,6 +22504,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
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 {
@@ -22666,6 +22666,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
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 {
@@ -18840,6 +18840,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
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");