aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-05-21 22:43:44 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-05-21 22:43:44 +0000
commit18df0eba838c7609d10edcb845ca6f35698e822c (patch)
tree1ac0a6dbc2370672633fc38090fd255f84c80045
parente6d11975d7182ee63ceb6a4f3ece4ee27efbba68 (diff)
objective-c: provide a useful 'fixit' suggestion when
errornously using commas to separate ObjC message arguments. // rdar://11376372 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157216 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticParseKinds.td2
-rw-r--r--lib/Parse/ParseObjc.cpp6
-rw-r--r--test/FixIt/fixit-objc-message-comma-separator.m17
3 files changed, 24 insertions, 1 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td
index ccd5074833..e251af43e4 100644
--- a/include/clang/Basic/DiagnosticParseKinds.td
+++ b/include/clang/Basic/DiagnosticParseKinds.td
@@ -378,6 +378,8 @@ def err_synthesized_property_name : Error<
def warn_semicolon_before_method_body : Warning<
"semicolon before method body is ignored">,
InGroup<DiagGroup<"semicolon-before-method-body">>, DefaultIgnore;
+def note_extra_comma_message_arg : Note<
+ "comma separating objective-c messaging arguments">;
def err_expected_field_designator : Error<
"expected a field designator, such as '.field = 4'">;
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 164c2f4055..f7efad5cd1 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -2452,10 +2452,14 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
}
// Parse the, optional, argument list, comma separated.
while (Tok.is(tok::comma)) {
- ConsumeToken(); // Eat the ','.
+ SourceLocation commaLoc = ConsumeToken(); // Eat the ','.
/// Parse the expression after ','
ExprResult Res(ParseAssignmentExpression());
if (Res.isInvalid()) {
+ if (Tok.is(tok::colon)) {
+ Diag(commaLoc, diag::note_extra_comma_message_arg) <<
+ FixItHint::CreateRemoval(commaLoc);
+ }
// We must manually skip to a ']', otherwise the expression skipper will
// stop at the ']' when it skips to the ';'. We want it to skip beyond
// the enclosing expression.
diff --git a/test/FixIt/fixit-objc-message-comma-separator.m b/test/FixIt/fixit-objc-message-comma-separator.m
new file mode 100644
index 0000000000..0caa33eb0a
--- /dev/null
+++ b/test/FixIt/fixit-objc-message-comma-separator.m
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fdiagnostics-parseable-fixits -x objective-c %s 2>&1 | FileCheck %s
+// rdar://11376372
+
+@class NSObject;
+
+@interface TestObj {
+}
+-(void)aMethodWithArg1:(NSObject*)arg1 arg2:(NSObject*)arg2;
+@end
+
+int main(int argc, char *argv[])
+{
+ TestObj *obj;
+ [obj aMethodWithArg1:@"Arg 1 Good", arg2:@"Arg 2 Good"];
+}
+
+// CHECK: {14:39-14:40}:""