Explicit declaration of property setters over-ride

prohibition of 'readonly' properties in an assignment.

llvm-svn: 62028
This commit is contained in:
Fariborz Jahanian 2009-01-10 18:43:55 +00:00
parent 776b2fa1ea
commit 8630b2d992
2 changed files with 32 additions and 1 deletions

View File

@ -257,7 +257,9 @@ void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
///
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
@ -265,6 +267,10 @@ bool ObjCInterfaceDecl::isPropertyReadonly(ObjCPropertyDecl *PDecl) const
// 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())

View File

@ -0,0 +1,25 @@
// 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