aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-11-17 22:29:32 +0000
committerSteve Naroff <snaroff@apple.com>2008-11-17 22:29:32 +0000
commit87d3ef08d892df8264bd51adb6ddd4a22422cd29 (patch)
tree835a75f06ee20df7e02f320ff4164cc2b6d9b2b7
parentc689836d760849c05194fe250c54e99a57706c72 (diff)
Fix <rdar://problem/6333904> [sema] message lookup on super is incorrect
Missing special lookup rule in Sema::ActOnInstanceMessage(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59467 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaExprObjC.cpp18
-rw-r--r--test/Analysis/PR2978.m1
-rw-r--r--test/SemaObjC/super.m25
3 files changed, 43 insertions, 1 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index bc2f7f2d6f..f6f3202ddb 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -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()) {
diff --git a/test/Analysis/PR2978.m b/test/Analysis/PR2978.m
index 69deec9860..aa5d173807 100644
--- a/test/Analysis/PR2978.m
+++ b/test/Analysis/PR2978.m
@@ -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
index 0000000000..46b8b4a097
--- /dev/null
+++ b/test/SemaObjC/super.m
@@ -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