Load default values for annotation members from classfiles
so that defaults are available to synthetic implementations. #KT-48181 Fixed Implementation is for JVM IR; other backends & FIR need to be supported separately.
This commit is contained in:
+6
@@ -78,4 +78,10 @@ interface AnnotationAndConstantLoader<out A : Any, out C : Any> {
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: KotlinType
|
||||
): C?
|
||||
|
||||
fun loadAnnotationDefaultValue(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: KotlinType
|
||||
): C?
|
||||
}
|
||||
|
||||
+9
@@ -104,4 +104,13 @@ class AnnotationAndConstantLoaderImpl(
|
||||
val value = proto.getExtensionOrNull(protocol.compileTimeValue) ?: return null
|
||||
return deserializer.resolveValue(expectedType, value, container.nameResolver)
|
||||
}
|
||||
|
||||
override fun loadAnnotationDefaultValue(
|
||||
container: ProtoContainer,
|
||||
proto: ProtoBuf.Property,
|
||||
expectedType: KotlinType
|
||||
): ConstantValue<*>? {
|
||||
// Implement this method to properly support Annotations Instantiation feature
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -140,6 +140,15 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
||||
)
|
||||
}
|
||||
|
||||
if ((c.containingDeclaration as? ClassDescriptor)?.kind == ClassKind.ANNOTATION_CLASS) {
|
||||
property.setCompileTimeInitializer(
|
||||
c.storageManager.createNullableLazyValue {
|
||||
val container = c.containingDeclaration.asProtoContainer()!!
|
||||
c.components.annotationAndConstantLoader.loadAnnotationDefaultValue(container, proto, property.returnType)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
property.initialize(
|
||||
getter, setter,
|
||||
FieldDescriptorImpl(getPropertyFieldAnnotations(proto, isDelegate = false), property),
|
||||
|
||||
Reference in New Issue
Block a user