JVM_IR: serialize anonymous functions' descriptors
This commit is contained in:
@@ -89,6 +89,7 @@ open class ClassCodegen protected constructor(
|
||||
when (val metadata = irClass.metadata) {
|
||||
is MetadataSource.Class -> DescriptorSerializer.create(metadata.descriptor, serializerExtension, parentClassCodegen?.serializer)
|
||||
is MetadataSource.File -> DescriptorSerializer.createTopLevel(serializerExtension)
|
||||
is MetadataSource.Function -> DescriptorSerializer.createForLambda(serializerExtension)
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -239,6 +240,15 @@ open class ClassCodegen protected constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
is MetadataSource.Function -> {
|
||||
val fakeDescriptor = createFreeFakeLambdaDescriptor(metadata.descriptor)
|
||||
val functionProto = serializer!!.functionProto(fakeDescriptor)?.build()
|
||||
writeKotlinMetadata(visitor, state, KotlinClassHeader.Kind.SYNTHETIC_CLASS, 0) {
|
||||
if (functionProto != null) {
|
||||
AsmUtil.writeAnnotationData(it, serializer, functionProto)
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val entry = irClass.fileParent.fileEntry
|
||||
if (entry is MultifileFacadeFileEntry) {
|
||||
|
||||
+4
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrClassReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
||||
@@ -144,6 +145,9 @@ internal class CallableReferenceLowering(private val context: JvmBackendContext)
|
||||
if (irFunctionReference.isSuspend) superTypes += context.ir.symbols.suspendFunctionInterface.defaultType
|
||||
createImplicitParameterDeclarationWithWrappedDescriptor()
|
||||
copyAttributes(irFunctionReference)
|
||||
if (isLambda) {
|
||||
(this as IrClassImpl).metadata = irFunctionReference.symbol.owner.metadata
|
||||
}
|
||||
}
|
||||
|
||||
private val receiverFieldFromSuper = context.ir.symbols.functionReferenceReceiverField.owner
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.reflect
|
||||
|
||||
class C {
|
||||
val x = { OK: String -> }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return C().x.reflect()?.parameters?.singleOrNull()?.name ?: "null"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.reflect
|
||||
|
||||
val x = { OK: String -> }
|
||||
|
||||
fun box(): String {
|
||||
return x.reflect()?.parameters?.singleOrNull()?.name ?: "null"
|
||||
}
|
||||
+10
@@ -23648,6 +23648,16 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
public void testParameterNamesAndNullability() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/parameterNamesAndNullability.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectOnLambdaInField.kt")
|
||||
public void testReflectOnLambdaInField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/reflectOnLambdaInField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectOnLambdaInStaticField.kt")
|
||||
public void testReflectOnLambdaInStaticField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/reflectOnLambdaInStaticField.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/mapping")
|
||||
|
||||
+10
@@ -22465,6 +22465,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
public void testParameterNamesAndNullability() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/parameterNamesAndNullability.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectOnLambdaInField.kt")
|
||||
public void testReflectOnLambdaInField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/reflectOnLambdaInField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectOnLambdaInStaticField.kt")
|
||||
public void testReflectOnLambdaInStaticField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/reflectOnLambdaInStaticField.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/mapping")
|
||||
|
||||
+10
@@ -22137,6 +22137,16 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
public void testParameterNamesAndNullability() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/parameterNamesAndNullability.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectOnLambdaInField.kt")
|
||||
public void testReflectOnLambdaInField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/reflectOnLambdaInField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectOnLambdaInStaticField.kt")
|
||||
public void testReflectOnLambdaInStaticField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/reflectOnLambdaInStaticField.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/mapping")
|
||||
|
||||
+10
@@ -22137,6 +22137,16 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
public void testParameterNamesAndNullability() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/parameterNamesAndNullability.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectOnLambdaInField.kt")
|
||||
public void testReflectOnLambdaInField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/reflectOnLambdaInField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("reflectOnLambdaInStaticField.kt")
|
||||
public void testReflectOnLambdaInStaticField() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/lambdaClasses/reflectOnLambdaInStaticField.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/reflection/mapping")
|
||||
|
||||
Reference in New Issue
Block a user