///
bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const
{
- if (!PDecl->isReadOnly())
+ // Even if property is ready only, if interface has a user defined setter,
+ // it is not considered read only.
+ if (!PDecl->isReadOnly() || getInstanceMethod(PDecl->getSetterName()))
return false;
// Main class has the property as 'readonly'. Must search
// attribute has been over-ridden to 'readwrite'.
for (ObjCCategoryDecl *Category = getCategoryList();
Category; Category = Category->getNextClassCategory()) {
+ // Even if property is ready only, if a category has a user defined setter,
+ // it is not considered read only.
+ if (Category->getInstanceMethod(PDecl->getSetterName()))
+ return false;
ObjCPropertyDecl *P =
Category->FindPropertyDeclaration(PDecl->getIdentifier());
if (P && !P->isReadOnly())
--- /dev/null
+// RUN: clang -fsyntax-only -verify %s
+
+@interface I0
+@property(readonly) int x;
+@property(readonly) int y;
+@property(readonly) int z;
+-(void) setY: (int) y0;
+@end
+
+@interface I0 (Cat0)
+-(void) setX: (int) a0;
+@end
+
+@implementation I0
+@dynamic x;
+@dynamic y;
+@dynamic z;
+-(void) setY: (int) y0{}
+
+-(void) im0 {
+ self.x = 0;
+ self.y = 2;
+ self.z = 2; // expected-error {{assigning to property with 'readonly' attribute not allowed}}
+}
+@end