]> granicus.if.org Git - clang/commitdiff
Patch to allow @dynamic synthesis of property in a category,
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 19 Jan 2009 18:16:19 +0000 (18:16 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 19 Jan 2009 18:16:19 +0000 (18:16 +0000)
with @synthesize being illegal.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62515 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclObjC.cpp
test/SemaObjC/property-category-2.m [new file with mode: 0644]

index ea7a047780c8e88b75bfa26a76fad2957d66b00b..90962e69bd15fff9d2accd0492e8e5f0eaf8416b 100644 (file)
@@ -364,8 +364,7 @@ ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
         return property;
   }
   
-  const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this);
-  if (OID) {
+  if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) {
     // Look through categories.
     for (ObjCCategoryDecl *Category = OID->getCategoryList();
          Category; Category = Category->getNextClassCategory()) {
@@ -384,6 +383,16 @@ ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
     if (OID->getSuperClass())
       return OID->getSuperClass()->FindPropertyDeclaration(PropertyId);
   }
+  else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) {
+    // Look through protocols.
+    for (ObjCInterfaceDecl::protocol_iterator I = OCD->protocol_begin(),
+         E = OCD->protocol_end(); I != E; ++I) {
+      ObjCProtocolDecl *Protocol = *I;
+      ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId);
+      if (property)
+        return property;
+    }
+  }
   return 0;
 }
 
diff --git a/test/SemaObjC/property-category-2.m b/test/SemaObjC/property-category-2.m
new file mode 100644 (file)
index 0000000..2b86a9e
--- /dev/null
@@ -0,0 +1,19 @@
+// RUN: clang -fsyntax-only -verify %s
+// Test that a property can be synthesize in a category
+// implementation with no error.
+
+@protocol MyProtocol
+@property float  myFloat;
+@property float  anotherFloat;
+@end
+
+@interface MyObject { float anotherFloat; }
+@end
+
+@interface MyObject (CAT) <MyProtocol>
+@end
+
+@implementation MyObject (CAT)
+@dynamic myFloat;      // OK
+@synthesize anotherFloat; // expected-error {{@synthesize not allowed in a category's implementation}}
+@end