]> granicus.if.org Git - clang/commitdiff
When we encounter a code-completion token while parsing an ill-formed
authorDouglas Gregor <dgregor@apple.com>
Tue, 31 Jul 2012 00:50:07 +0000 (00:50 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 31 Jul 2012 00:50:07 +0000 (00:50 +0000)
lambda-introducer in Objective-C++11, fall back to treating the tokens
as an Objective-C message send to provide those (more likely)
completions. Fixes <rdar://problem/11980263>.

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

lib/Parse/ParseExprCXX.cpp
test/Index/complete-lambdas.mm [new file with mode: 0644]

index b393d1ff67ce34f485edbb6e7355096639c84662..b1ce59f28c778b88b93f5f363e553a1d9e95c0e7 100644 (file)
@@ -642,7 +642,11 @@ llvm::Optional<unsigned> Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro){
   while (Tok.isNot(tok::r_square)) {
     if (!first) {
       if (Tok.isNot(tok::comma)) {
-        if (Tok.is(tok::code_completion)) {
+        // Provide a completion for a lambda introducer here. Except
+        // in Objective-C, where this is Almost Surely meant to be a message
+        // send. In that case, fail here and let the ObjC message
+        // expression parser perform the completion.
+        if (Tok.is(tok::code_completion) && !getLangOpts().ObjC1) {
           Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro, 
                                                /*AfterAmpersand=*/false);
           ConsumeCodeCompletionToken();
diff --git a/test/Index/complete-lambdas.mm b/test/Index/complete-lambdas.mm
new file mode 100644 (file)
index 0000000..5f33906
--- /dev/null
@@ -0,0 +1,40 @@
+// This test is line- and column-sensitive. See below for run lines.
+
+
+@interface A
+- instanceMethod:(int)value withOther:(int)other;
++ classMethod;
+@end
+
+@interface B : A
+@end
+
+@implementation B
+- someMethod:(A*)a {
+  [a classMethod];
+  [A classMethod];
+  [a instanceMethod:0 withOther:1];
+  [self someMethod:a];
+  [super instanceMethod];
+}
+
+@end
+
+// RUN: c-index-test -code-completion-at=%s:14:6 -std=c++11 %s | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: ObjCInstanceMethodDecl:{ResultType id}{TypedText instanceMethod:}{Placeholder (int)}{HorizontalSpace  }{TypedText withOther:}{Placeholder (int)} (35) (parent: ObjCInterfaceDecl 'A')
+
+// RUN: c-index-test -code-completion-at=%s:15:6 -std=c++11 %s | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: ObjCClassMethodDecl:{ResultType id}{TypedText classMethod} (35) (parent: ObjCInterfaceDecl 'A')
+
+// RUN: c-index-test -code-completion-at=%s:16:4 -std=c++11 %s | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: ObjCInterfaceDecl:{TypedText A} (50) (parent: TranslationUnit '(null)')
+// CHECK-CC3: ParmDecl:{ResultType A *}{TypedText a} (34)
+// CHECK-CC3: ObjCInterfaceDecl:{TypedText B} (50) (parent: TranslationUnit '(null)')
+// CHECK-CC3: TypedefDecl:{TypedText Class} (50) (parent: TranslationUnit '(null)')
+
+
+// RUN: c-index-test -code-completion-at=%s:16:21 -x objective-c++ -std=c++11 %s | FileCheck -check-prefix=CHECK-CC4 %s
+// CHECK-CC4: NotImplemented:{ResultType B *}{TypedText self} (34)
+// CHECK-CC4: NotImplemented:{ResultType A *}{TypedText super} (40)
+
+// RUN: c-index-test -code-completion-at=%s:18:10 -x objective-c++ -std=c++11 %s | FileCheck -check-prefix=CHECK-CC1 %s