]> granicus.if.org Git - clang/commitdiff
Diagnose bad receiver type.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 25 Jan 2008 17:43:39 +0000 (17:43 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 25 Jan 2008 17:43:39 +0000 (17:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46358 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaExprObjC.cpp
include/clang/Basic/DiagnosticKinds.def
test/Sema/objc-bad-receiver-1.m [new file with mode: 0644]

index 125a4c4f9d9cefe327688dbd1b607885159457e4..f4d16d9736c0c76e93ca93891044fbd11b9bdc98 100644 (file)
@@ -258,8 +258,10 @@ Sema::ExprResult Sema::ActOnInstanceMessage(
              SourceRange(lbrac, rbrac));
     }
     else {
-      assert(ObjCInterfaceType::classof(receiverType.getTypePtr()) &&
-             "bad receiver type");
+      if (!isa<ObjCInterfaceType>(receiverType.getTypePtr())) {
+        Diag(lbrac, diag::error_bad_receiver_type, receiverType.getAsString());
+        return true;
+      }
       ClassDecl = static_cast<ObjCInterfaceType*>(
                     receiverType.getTypePtr())->getDecl();
       // FIXME: consider using InstanceMethodPool, since it will be faster
index 53d49460492cb15945681cef109fbec881c9d3f8..81f9b97544b570c2d32d67f36257dfa8cdc79d54 100644 (file)
@@ -482,6 +482,8 @@ DIAG(err_toomany_element_decls, ERROR,
      "Only one element declaration is allowed")
 DIAG(warn_expected_implementation, WARNING,
      "@end must appear in an @implementation context")
+DIAG(error_bad_receiver_type, ERROR,
+     "bad receiver type (its type is '%0')")
 
 //===----------------------------------------------------------------------===//
 // Semantic Analysis
diff --git a/test/Sema/objc-bad-receiver-1.m b/test/Sema/objc-bad-receiver-1.m
new file mode 100644 (file)
index 0000000..b181908
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface I
+- (id) retain;
+@end
+
+void __raiseExc1() {
+ [objc_lookUpClass("NSString") retain]; // expected-error {{ "bad receiver type (its type is 'int')" }}
+}