From: Alex Lorenz Date: Wed, 23 Nov 2016 16:28:34 +0000 (+0000) Subject: [CodeCompletion] Fix incorrect Objective-C block parameter formatting X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=703d1c6a5d95b747d5c80c7b271d5d4bef5bfd35;p=clang [CodeCompletion] Fix incorrect Objective-C block parameter formatting This commit fixes an incorrectly formatted Objective-C block parameter placeholder in a code completion result. The incorrect parameter had a redundant leading parenthesis. rdar://25224416 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287771 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaCodeComplete.cpp b/lib/Sema/SemaCodeComplete.cpp index 9f770cee03..2a78c981b4 100644 --- a/lib/Sema/SemaCodeComplete.cpp +++ b/lib/Sema/SemaCodeComplete.cpp @@ -2264,9 +2264,13 @@ static std::string FormatFunctionParameter(const PrintingPolicy &Policy, QualType Type = Param->getType().getUnqualifiedType(); if (ObjCMethodParam) { - Result = "(" + formatObjCParamQualifiers(Param->getObjCDeclQualifier(), - Type); - Result += Type.getAsString(Policy) + Result + ")"; + Result = Type.getAsString(Policy); + std::string Quals = + formatObjCParamQualifiers(Param->getObjCDeclQualifier(), Type); + if (!Quals.empty()) + Result = "(" + Quals + " " + Result + ")"; + if (Result.back() != ')') + Result += " "; if (Param->getIdentifier()) Result += Param->getIdentifier()->getName(); } else { @@ -2275,7 +2279,7 @@ static std::string FormatFunctionParameter(const PrintingPolicy &Policy, return Result; } - + // We have the function prototype behind the block pointer type, as it was // written in the source. return formatBlockPlaceholder(Policy, Param, Block, BlockProto, diff --git a/test/Index/complete-block-properties.m b/test/Index/complete-block-properties.m index ce97a453c5..47eee02ba5 100644 --- a/test/Index/complete-block-properties.m +++ b/test/Index/complete-block-properties.m @@ -51,3 +51,22 @@ typedef int (^BarBlock)(int *); //CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType int}{TypedText performB}{LeftParen (}{Placeholder int x}{Comma , }{Placeholder int y}{RightParen )} (35) @end + +// rdar://25224416 + +@interface NoQualifierParens + +@property(copy) void (^blockProperty)(void); +@property BarBlock blockProperty2; + +@end + +void noQualifierParens(NoQualifierParens *f) { + [f setBlockProperty: ^{}]; +} + +// RUN: c-index-test -code-completion-at=%s:65:6 %s | FileCheck -check-prefix=CHECK-CC2 %s +//CHECK-CC2: ObjCInstanceMethodDecl:{ResultType void (^)(void)}{TypedText blockProperty} (35) +//CHECK-CC2-NEXT: ObjCInstanceMethodDecl:{ResultType BarBlock}{TypedText blockProperty2} (35) +//CHECK-CC2-NEXT: ObjCInstanceMethodDecl:{ResultType void}{TypedText setBlockProperty2:}{Placeholder BarBlock blockProperty2} (35) +//CHECK-CC2-NEXT: ObjCInstanceMethodDecl:{ResultType void}{TypedText setBlockProperty:}{Placeholder void (^)(void)blockProperty} (35)