@@ -2575,7 +2575,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2575
2575
if (!consumeIf (tok::r_paren, ownershipLocEnd))
2576
2576
diagnose (Tok, diag::attr_unowned_expected_rparen);
2577
2577
}
2578
- } else if (Tok.isAny (tok::identifier, tok::kw_self) &&
2578
+ } else if (Tok.isAny (tok::identifier, tok::kw_self, tok::code_complete ) &&
2579
2579
peekToken ().isAny (tok::equal, tok::comma, tok::r_square)) {
2580
2580
// "x = 42", "x," and "x]" are all strong captures of x.
2581
2581
} else {
@@ -2584,7 +2584,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2584
2584
continue ;
2585
2585
}
2586
2586
2587
- if (Tok.isNot (tok::identifier, tok::kw_self)) {
2587
+ if (Tok.isNot (tok::identifier, tok::kw_self, tok::code_complete )) {
2588
2588
diagnose (Tok, diag::expected_capture_specifier_name);
2589
2589
skipUntil (tok::comma, tok::r_square);
2590
2590
continue ;
@@ -2602,10 +2602,20 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2602
2602
if (peekToken ().isNot (tok::equal)) {
2603
2603
// If this is the simple case, then the identifier is both the name and
2604
2604
// the expression to capture.
2605
- name = Context.getIdentifier (Tok.getText ());
2606
- auto initializerResult = parseExprIdentifier ();
2607
- status |= initializerResult;
2608
- initializer = initializerResult.get ();
2605
+ if (!Tok.is (tok::code_complete)) {
2606
+ name = Context.getIdentifier (Tok.getText ());
2607
+ auto initializerResult = parseExprIdentifier ();
2608
+ status |= initializerResult;
2609
+ initializer = initializerResult.get ();
2610
+ } else {
2611
+ auto CCE = new (Context) CodeCompletionExpr (Tok.getLoc ());
2612
+ if (CodeCompletion)
2613
+ CodeCompletion->completePostfixExprBeginning (CCE);
2614
+ name = Identifier ();
2615
+ initializer = CCE;
2616
+ consumeToken ();
2617
+ status.setHasCodeCompletion ();
2618
+ }
2609
2619
2610
2620
// It is a common error to try to capture a nested field instead of just
2611
2621
// a local name, reject it with a specific error message.
@@ -2617,7 +2627,13 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2617
2627
2618
2628
} else {
2619
2629
// Otherwise, the name is a new declaration.
2620
- consumeIdentifier (name, /* diagnoseDollarPrefix=*/ true );
2630
+ if (!Tok.is (tok::code_complete)) {
2631
+ consumeIdentifier (name, /* diagnoseDollarPrefix=*/ true );
2632
+ } else {
2633
+ // Ignore completion token because it's a new declaration.
2634
+ name = Identifier ();
2635
+ consumeToken (tok::code_complete);
2636
+ }
2621
2637
equalLoc = consumeToken (tok::equal);
2622
2638
2623
2639
auto ExprResult = parseExpr (diag::expected_init_capture_specifier);
0 commit comments