]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6252129> implementation of method in category doesn't effectively...
authorSteve Naroff <snaroff@apple.com>
Sun, 28 Sep 2008 14:55:53 +0000 (14:55 +0000)
committerSteve Naroff <snaroff@apple.com>
Sun, 28 Sep 2008 14:55:53 +0000 (14:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56771 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExprObjC.cpp
test/SemaObjC/category-method-lookup.m [new file with mode: 0644]

index f553629a6c9305cfe411c8d922856a3f55aa58e3..dcd197dad6feae4f4e9054c62e36d7e5708f7795 100644 (file)
@@ -92,10 +92,14 @@ public:
   /// This is only necessary for issuing pretty diagnostics.
   llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
 
-  /// ObjCImplementations - Keep track of all of the classes with
-  /// @implementation's, so that we can emit errors on duplicates.
+  /// ObjCImplementations - Keep track of all class @implementations
+  /// so we can emit errors on duplicates.
   llvm::DenseMap<IdentifierInfo*, ObjCImplementationDecl*> ObjCImplementations;
   
+  /// ObjCCategoryImpls - Maintain a list of category implementations so 
+  /// we can check for duplicates and find local method declarations.
+  llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
+  
   /// ObjCProtocols - Keep track of all protocol declarations declared
   /// with @protocol keyword, so that we can emit errors on duplicates and
   /// find the declarations when needed.
index a09daa0814b5ecf50b62aa179b2bd8a36e2825fe..024165502658938898526fe75799801d011ef182 100644 (file)
@@ -429,6 +429,7 @@ Sema::DeclTy *Sema::ActOnStartCategoryImplementation(
 
   /// TODO: Check that CatName, category name, is not used in another
   // implementation.
+  ObjCCategoryImpls.push_back(CDecl);
   return CDecl;
 }
 
index 390baed9a33521f7df4ef71e6fc3f64f942bc4af..a2a3992bab5908a6035391360e5b67f27212f8f0 100644 (file)
@@ -233,6 +233,14 @@ Sema::ExprResult Sema::ActOnClassMessage(
     if (ObjCImplementationDecl *ImpDecl = 
         ObjCImplementations[ClassDecl->getIdentifier()])
       Method = ImpDecl->getClassMethod(Sel);
+      
+    // Look through local category implementations associated with the class.
+    if (!Method) {
+      for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Method; i++) {
+        if (ObjCCategoryImpls[i]->getClassInterface() == ClassDecl)
+          Method = ObjCCategoryImpls[i]->getClassMethod(Sel);
+      }
+    }
   }
   // Before we give up, check if the selector is an instance method.
   if (!Method)
diff --git a/test/SemaObjC/category-method-lookup.m b/test/SemaObjC/category-method-lookup.m
new file mode 100644 (file)
index 0000000..a709008
--- /dev/null
@@ -0,0 +1,31 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface Foo
+@end
+@implementation Foo
+@end
+
+@implementation Foo(Whatever)
++(float)returnsFloat { return 7.0; }
+@end
+
+@interface Foo (MoreStuff)
++(int)returnsInt;
+@end
+
+@implementation Foo (MoreStuff)
++(int)returnsInt {
+  return 0;
+}
+
++(void)returnsNothing {
+}
+-(int)callsReturnsInt {
+  float f = [Foo returnsFloat]; // GCC doesn't find this method (which is a bug IMHO).
+  [Foo returnsNothing];
+  return [Foo returnsInt];
+}
+@end
+
+int main() {return 0;}
+