]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6333904> [sema] message lookup on super is incorrect
authorSteve Naroff <snaroff@apple.com>
Mon, 17 Nov 2008 22:29:32 +0000 (22:29 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 17 Nov 2008 22:29:32 +0000 (22:29 +0000)
Missing special lookup rule in Sema::ActOnInstanceMessage().

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

lib/Sema/SemaExprObjC.cpp
test/Analysis/PR2978.m
test/SemaObjC/super.m [new file with mode: 0644]

index bc2f7f2d6f74f03d893cba9f77566c2812255732..f6f3202ddb02b27fd3e826c0ed9fbd2408ad1e2a 100644 (file)
@@ -278,7 +278,23 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
 
   QualType ReceiverCType =
     Context.getCanonicalType(RExpr->getType()).getUnqualifiedType();
-  
+
+  // Handle messages to 'super'.
+  if (isa<ObjCSuperExpr>(RExpr)) {
+    ObjCMethodDecl *Method = 0;
+    if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
+      // If we have an interface in scope, check 'super' methods.
+      if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface())
+        if (ObjCInterfaceDecl *SuperDecl = ClassDecl->getSuperClass())
+          Method = SuperDecl->lookupInstanceMethod(Sel);
+    }
+    if (CheckMessageArgumentTypes(ArgExprs, NumArgs, Sel, Method, "-", 
+                                  lbrac, rbrac, returnType))
+      return true;
+    return new ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac, rbrac, 
+                               ArgExprs, NumArgs);
+  }
+
   // Handle messages to id.
   if (ReceiverCType == Context.getCanonicalType(Context.getObjCIdType()) ||
       ReceiverCType->getAsBlockPointerType()) {
index 69deec9860d7c0b3dc68349536ca2148d2f14207..aa5d173807b2d6f2767bcf10eaa6aae8cb6ec9fe 100644 (file)
@@ -5,6 +5,7 @@
 
 @interface NSObject
 - (void)release;
+- dealloc;
 @end
 
 @interface MyClass : NSObject {
diff --git a/test/SemaObjC/super.m b/test/SemaObjC/super.m
new file mode 100644 (file)
index 0000000..46b8b4a
--- /dev/null
@@ -0,0 +1,25 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface Foo
+- iMethod;
++ cMethod;
+@end
+
+@interface A
+@end
+
+@interface B : A
+- (void)instanceMethod;
++ classMethod;
+@end
+
+@implementation B
+
+- (void)instanceMethod {
+  [super iMethod]; // expected-warning{{method '-iMethod' not found (return type defaults to 'id')}}
+}
+
++ classMethod {
+  [super cMethod]; // expected-warning{{method '+cMethod' not found (return type defaults to 'id')}}
+}
+@end