Do not generate metadata for callable reference classes
After an accidental change in 846537b367, we started generating metadata
into anonymous classes for callable references. This metadata contained
the Kotlin representation of the referenced function. In KT-53794, this
led to a problem where Java's protected visibility could not be
represented in Kotlin terms, which crashed the backend.
But also, this metadata is useless because there's no real use case for
interpreting it (since you already have a function reference object at
runtime with all the needed information), so it would take some extra
space in the bytecode.
#KT-53794 Fixed
This commit is contained in:
+6
@@ -4116,6 +4116,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/kt47741.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53794_protectedJavaMember.kt")
|
||||
public void testKt53794_protectedJavaMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/kt53794_protectedJavaMember.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nestedConstructorFromClass.kt")
|
||||
public void testNestedConstructorFromClass() throws Exception {
|
||||
|
||||
+6
@@ -958,6 +958,12 @@ public class FirBytecodeTextTestGenerated extends AbstractFirBytecodeTextTest {
|
||||
runTest("compiler/testData/codegen/bytecodeText/callableReference/nameIntrinsicWithImplicitThis.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noMetadata.kt")
|
||||
public void testNoMetadata() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/callableReference/noMetadata.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unboundFieldReferenceInInline.kt")
|
||||
public void testUnboundFieldReferenceInInline() throws Exception {
|
||||
|
||||
+1
-1
@@ -545,7 +545,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
|
||||
}
|
||||
createImplicitParameterDeclarationWithWrappedDescriptor()
|
||||
copyAttributes(irFunctionReference)
|
||||
if (!isLightweightLambda) {
|
||||
if (isHeavyweightLambda) {
|
||||
metadata = irFunctionReference.symbol.owner.metadata
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: B.kt
|
||||
|
||||
class B : C() {
|
||||
fun test(): String = bar(this::foo)
|
||||
}
|
||||
|
||||
fun bar(f: () -> String): String = f()
|
||||
|
||||
fun box(): String = B().test()
|
||||
|
||||
// FILE: C.java
|
||||
|
||||
public class C {
|
||||
protected final String foo() {
|
||||
return "OK";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
|
||||
fun f() {}
|
||||
fun g() = ::f
|
||||
|
||||
// This regexp checks that there's only one class annotated with kotlin.Metadata with the actual data (which is in the `d1` field).
|
||||
// That class is the file facade. The synthetic class for the reference `::f` should be generated with synthetic metadata, i.e.
|
||||
// which has nothing in the `d1` field.
|
||||
// 1 @Lkotlin/Metadata;\(.*d1.*\)
|
||||
+6
@@ -4002,6 +4002,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/kt47741.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53794_protectedJavaMember.kt")
|
||||
public void testKt53794_protectedJavaMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/kt53794_protectedJavaMember.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nestedConstructorFromClass.kt")
|
||||
public void testNestedConstructorFromClass() throws Exception {
|
||||
|
||||
+6
@@ -4116,6 +4116,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/kt47741.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt53794_protectedJavaMember.kt")
|
||||
public void testKt53794_protectedJavaMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/kt53794_protectedJavaMember.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nestedConstructorFromClass.kt")
|
||||
public void testNestedConstructorFromClass() throws Exception {
|
||||
|
||||
+6
@@ -958,6 +958,12 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
||||
runTest("compiler/testData/codegen/bytecodeText/callableReference/nameIntrinsicWithImplicitThis.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noMetadata.kt")
|
||||
public void testNoMetadata() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeText/callableReference/noMetadata.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unboundFieldReferenceInInline.kt")
|
||||
public void testUnboundFieldReferenceInInline() throws Exception {
|
||||
|
||||
+5
@@ -3498,6 +3498,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/kt47741.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt53794_protectedJavaMember.kt")
|
||||
public void testKt53794_protectedJavaMember() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/kt53794_protectedJavaMember.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedConstructorFromClass.kt")
|
||||
public void testNestedConstructorFromClass() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/callableReference/function/nestedConstructorFromClass.kt");
|
||||
|
||||
Reference in New Issue
Block a user