Consider property accessor non-default if it has annotations
Otherwise we're not trying to load annotations on the parameter of the property setter in MemberDeserializer.loadProperty. Note that after this commit, we could now also assume that if getter/setter is default, it has no annotations, and thus use Annotations.EMPTY for default getter/setter in loadProperty. However, this would cause reflection to work incorrectly on classes compiled by an older Kotlin compiler, so we'll still try to load annotations on default accessors for an indefinite time. #KT-25499 Fixed
This commit is contained in:
@@ -1038,10 +1038,13 @@ public class DescriptorResolver {
|
||||
boolean hasDelegate
|
||||
) {
|
||||
PropertySetterDescriptorImpl setterDescriptor = null;
|
||||
Annotations setterTargetedAnnotations = annotationSplitter.getAnnotationsForTarget(PROPERTY_SETTER);
|
||||
Annotations parameterTargetedAnnotations = annotationSplitter.getAnnotationsForTarget(SETTER_PARAMETER);
|
||||
if (setter != null) {
|
||||
Annotations annotations = new CompositeAnnotations(CollectionsKt.listOf(
|
||||
annotationSplitter.getAnnotationsForTarget(PROPERTY_SETTER),
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scopeWithTypeParameters, setter.getModifierList(), trace)));
|
||||
setterTargetedAnnotations,
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scopeWithTypeParameters, setter.getModifierList(), trace)
|
||||
));
|
||||
KtParameter parameter = setter.getParameter();
|
||||
|
||||
setterDescriptor = new PropertySetterDescriptorImpl(
|
||||
@@ -1082,8 +1085,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
ValueParameterDescriptorImpl valueParameterDescriptor = resolveValueParameterDescriptor(
|
||||
scopeWithTypeParameters, setterDescriptor, parameter, 0, type, trace,
|
||||
annotationSplitter.getAnnotationsForTarget(SETTER_PARAMETER)
|
||||
scopeWithTypeParameters, setterDescriptor, parameter, 0, type, trace, parameterTargetedAnnotations
|
||||
);
|
||||
setterDescriptor.initialize(valueParameterDescriptor);
|
||||
}
|
||||
@@ -1095,10 +1097,9 @@ public class DescriptorResolver {
|
||||
}
|
||||
else if (property.isVar()) {
|
||||
setterDescriptor = DescriptorFactory.createSetter(
|
||||
propertyDescriptor,
|
||||
annotationSplitter.getAnnotationsForTarget(PROPERTY_SETTER),
|
||||
annotationSplitter.getAnnotationsForTarget(SETTER_PARAMETER),
|
||||
!hasDelegate, false, property.hasModifier(KtTokens.INLINE_KEYWORD),
|
||||
propertyDescriptor, setterTargetedAnnotations, parameterTargetedAnnotations,
|
||||
!hasDelegate && setterTargetedAnnotations.isEmpty() && parameterTargetedAnnotations.isEmpty(),
|
||||
false, property.hasModifier(KtTokens.INLINE_KEYWORD),
|
||||
propertyDescriptor.getSource()
|
||||
);
|
||||
}
|
||||
@@ -1124,10 +1125,12 @@ public class DescriptorResolver {
|
||||
) {
|
||||
PropertyGetterDescriptorImpl getterDescriptor;
|
||||
KotlinType getterType;
|
||||
Annotations getterTargetedAnnotations = annotationSplitter.getAnnotationsForTarget(PROPERTY_GETTER);
|
||||
if (getter != null) {
|
||||
Annotations getterAnnotations = new CompositeAnnotations(CollectionsKt.listOf(
|
||||
annotationSplitter.getAnnotationsForTarget(PROPERTY_GETTER),
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scopeForDeclarationResolution, getter.getModifierList(), trace)));
|
||||
getterTargetedAnnotations,
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scopeForDeclarationResolution, getter.getModifierList(), trace)
|
||||
));
|
||||
|
||||
getterDescriptor = new PropertyGetterDescriptorImpl(
|
||||
propertyDescriptor, getterAnnotations,
|
||||
@@ -1142,9 +1145,11 @@ public class DescriptorResolver {
|
||||
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
||||
}
|
||||
else {
|
||||
Annotations getterAnnotations = annotationSplitter.getAnnotationsForTarget(PROPERTY_GETTER);
|
||||
getterDescriptor = DescriptorFactory.createGetter(propertyDescriptor, getterAnnotations, !hasDelegate,
|
||||
/* isExternal = */ false, property.hasModifier(KtTokens.INLINE_KEYWORD));
|
||||
getterDescriptor = DescriptorFactory.createGetter(
|
||||
propertyDescriptor, getterTargetedAnnotations,
|
||||
!hasDelegate && getterTargetedAnnotations.isEmpty(),
|
||||
/* isExternal = */ false, property.hasModifier(KtTokens.INLINE_KEYWORD)
|
||||
);
|
||||
getterType = propertyTypeIfKnown;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,8 +60,9 @@ object ConstModifierChecker : DeclarationChecker {
|
||||
return Errors.CONST_VAL_WITH_DELEGATE.on(declaration.delegate!!).nonApplicable()
|
||||
}
|
||||
|
||||
if (!descriptor.getter!!.isDefault) {
|
||||
return Errors.CONST_VAL_WITH_GETTER.on(declaration.getter!!).nonApplicable()
|
||||
val getter = declaration.getter
|
||||
if (!descriptor.getter!!.isDefault && getter != null) {
|
||||
return Errors.CONST_VAL_WITH_GETTER.on(getter).nonApplicable()
|
||||
}
|
||||
|
||||
if (descriptor.type.isError) return ConstApplicability.NonApplicable()
|
||||
|
||||
Reference in New Issue
Block a user