]> granicus.if.org Git - clang/commitdiff
Diagnose when accessing property in a class method and
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 3 Dec 2010 23:37:08 +0000 (23:37 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 3 Dec 2010 23:37:08 +0000 (23:37 +0000)
no property accessor class method to be found, instead of
crashing in IRGen. // rdar://8703553

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

include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprObjC.cpp
test/SemaObjC/property-impl-misuse.m

index 16d3a103594e66c8932b72da75cebcb27186cdc8..8282e0aab5dc23b743b74e0b4fa479582b3831b5 100644 (file)
@@ -639,7 +639,7 @@ public:
   ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
   
   // Lookup a method in the classes implementation hierarchy.
-  ObjCMethodDecl *lookupPrivateInstanceMethod(const Selector &Sel);
+  ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel, bool Instance=true);
 
   // Location information, modeled after the Stmt API.
   SourceLocation getLocStart() const { return getLocation(); } // '@'interface
index ea8fd4ae89dd68c364a9d9cccf84ddcc30777443..45f5188d4043f0ffd6296981db9fc970522ff6ba 100644 (file)
@@ -311,14 +311,16 @@ ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
   return NULL;
 }
 
-ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateInstanceMethod(
-                                   const Selector &Sel) {
+ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateMethod(
+                                   const Selector &Sel,
+                                   bool Instance) {
   ObjCMethodDecl *Method = 0;
   if (ObjCImplementationDecl *ImpDecl = getImplementation())
-    Method = ImpDecl->getInstanceMethod(Sel);
+    Method = Instance ? ImpDecl->getInstanceMethod(Sel) 
+                      : ImpDecl->getClassMethod(Sel);
   
   if (!Method && getSuperClass())
-    return getSuperClass()->lookupPrivateInstanceMethod(Sel);
+    return getSuperClass()->lookupPrivateMethod(Sel, Instance);
   return Method;
 }
 
index 9102cac8791017f2bcaa64dabaa57c238fd1dc13..270aa3e06b4b475cc82221a62d7eaa87ff16785c 100644 (file)
@@ -3498,12 +3498,13 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr,
     if (ObjCMethodDecl *MD = getCurMethodDecl()) {
       ObjCInterfaceDecl *IFace = MD->getClassInterface();
       ObjCMethodDecl *Getter;
-      // FIXME: need to also look locally in the implementation.
       if ((Getter = IFace->lookupClassMethod(Sel))) {
         // Check the use of this method.
         if (DiagnoseUseOfDecl(Getter, MemberLoc))
           return ExprError();
       }
+      else
+        Getter = IFace->lookupPrivateMethod(Sel, false);
       // If we found a getter then this may be a valid dot-reference, we
       // will look for the matching setter, in case it is needed.
       Selector SetterSel =
@@ -3513,7 +3514,7 @@ Sema::LookupMemberExpr(LookupResult &R, Expr *&BaseExpr,
       if (!Setter) {
         // If this reference is in an @implementation, also check for 'private'
         // methods.
-        Setter = IFace->lookupPrivateInstanceMethod(SetterSel);
+        Setter = IFace->lookupPrivateMethod(SetterSel, false);
       }
       // Look through local category implementations associated with the class.
       if (!Setter)
index 46a834a487490ac6151f302ec987df642fa2013a..e60aa071e2d3c34eaf9320a9b1ccdb343da24ff8 100644 (file)
@@ -402,7 +402,7 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
 
   // If this reference is in an @implementation, check for 'private' methods.
   if (!Getter)
-    Getter = IFace->lookupPrivateInstanceMethod(Sel);
+    Getter = IFace->lookupPrivateMethod(Sel);
 
   // Look through local category implementations associated with the class.
   if (!Getter)
@@ -421,7 +421,7 @@ HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT,
   if (!Setter) {
     // If this reference is in an @implementation, also check for 'private'
     // methods.
-    Setter = IFace->lookupPrivateInstanceMethod(SetterSel);
+    Setter = IFace->lookupPrivateMethod(SetterSel);
   }
   // Look through local category implementations associated with the class.
   if (!Setter)
index 58c91c59d05e90c8293a63c364146027b8998e16..122afc1d4b5be6c061cecc868f1a21fb514eaf4f 100644 (file)
 @synthesize Y; // expected-note {{previous use is here}}
 @synthesize Z=Y; // expected-error {{synthesized properties 'Z' and 'Y' both claim ivar 'Y'}}
 @end
+
+// rdar://8703553
+@interface IDEPathCell 
+{
+@private
+    id _gradientStyle;
+}
+
+@property (readwrite, assign, nonatomic) id gradientStyle;
+@end
+
+@implementation IDEPathCell
+
+@synthesize gradientStyle = _gradientStyle;
+- (void)setGradientStyle:(id)value { }
+
++ (void)_componentCellWithRepresentedObject {
+    self.gradientStyle; // expected-error {{property 'gradientStyle' not found on object of type 'Class'}}
+}
+@end