@@ -2323,14 +2323,14 @@ static void printTupleNames(const TypeRepr *typeRepr, llvm::raw_ostream &OS) {
2323
2323
OS << " )" ;
2324
2324
}
2325
2325
2326
- bool Parser::
2327
- parseClosureSignatureIfPresent ( SourceRange &bracketRange,
2328
- SmallVectorImpl<CaptureListEntry> &captureList,
2329
- VarDecl *&capturedSelfDecl,
2330
- ParameterList *¶ms,
2331
- SourceLoc &asyncLoc, SourceLoc &throwsLoc,
2332
- SourceLoc &arrowLoc,
2333
- TypeExpr *&explicitResultType, SourceLoc &inLoc){
2326
+ ParserStatus Parser::parseClosureSignatureIfPresent (
2327
+ SourceRange &bracketRange,
2328
+ SmallVectorImpl<CaptureListEntry> &captureList,
2329
+ VarDecl *&capturedSelfDecl,
2330
+ ParameterList *¶ms,
2331
+ SourceLoc &asyncLoc, SourceLoc &throwsLoc,
2332
+ SourceLoc &arrowLoc,
2333
+ TypeExpr *&explicitResultType, SourceLoc &inLoc) {
2334
2334
// Clear out result parameters.
2335
2335
bracketRange = SourceRange ();
2336
2336
capturedSelfDecl = nullptr ;
@@ -2342,19 +2342,21 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2342
2342
2343
2343
// Consume 'async', 'throws', and 'rethrows', but in any order.
2344
2344
auto consumeAsyncThrows = [&] {
2345
- bool hadAsync = false ;
2346
- if (shouldParseExperimentalConcurrency () &&
2347
- Tok.isContextualKeyword (" async" )) {
2348
- consumeToken ();
2349
- hadAsync = true ;
2350
- }
2345
+ while (true ) {
2346
+ if (shouldParseExperimentalConcurrency () &&
2347
+ Tok.isContextualKeyword (" async" )) {
2348
+ consumeToken ();
2349
+ continue ;
2350
+ }
2351
+ if (consumeIf (tok::kw_throws) || consumeIf (tok::kw_rethrows))
2352
+ continue ;
2351
2353
2352
- if (!consumeIf (tok::kw_throws) && !consumeIf (tok::kw_rethrows))
2353
- return ;
2354
+ if (Tok.is (tok::code_complete) && !Tok.isAtStartOfLine ()) {
2355
+ consumeToken ();
2356
+ continue ;
2357
+ }
2354
2358
2355
- if (shouldParseExperimentalConcurrency () && !hadAsync &&
2356
- Tok.isContextualKeyword (" async" )) {
2357
- consumeToken ();
2359
+ break ;
2358
2360
}
2359
2361
};
2360
2362
@@ -2367,7 +2369,7 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2367
2369
if (consumeIf (tok::l_square)) {
2368
2370
skipUntil (tok::r_square);
2369
2371
if (!consumeIf (tok::r_square))
2370
- return false ;
2372
+ return makeParserSuccess () ;
2371
2373
}
2372
2374
2373
2375
// Parse pattern-tuple func-signature-result? 'in'.
@@ -2384,7 +2386,7 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2384
2386
// Parse the func-signature-result, if present.
2385
2387
if (consumeIf (tok::arrow)) {
2386
2388
if (!canParseType ())
2387
- return false ;
2389
+ return makeParserSuccess () ;
2388
2390
}
2389
2391
}
2390
2392
@@ -2398,27 +2400,28 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2398
2400
continue ;
2399
2401
}
2400
2402
2401
- return false ;
2403
+ return makeParserSuccess () ;
2402
2404
}
2403
2405
2404
2406
consumeAsyncThrows ();
2405
2407
2406
2408
// Parse the func-signature-result, if present.
2407
2409
if (consumeIf (tok::arrow)) {
2408
2410
if (!canParseType ())
2409
- return false ;
2411
+ return makeParserSuccess () ;
2410
2412
}
2411
2413
}
2412
2414
2413
2415
// Parse the 'in' at the end.
2414
2416
if (Tok.isNot (tok::kw_in))
2415
- return false ;
2417
+ return makeParserSuccess () ;
2416
2418
2417
2419
// Okay, we have a closure signature.
2418
2420
} else {
2419
2421
// No closure signature.
2420
- return false ;
2422
+ return makeParserSuccess () ;
2421
2423
}
2424
+ ParserStatus status;
2422
2425
SyntaxParsingContext ClosureSigCtx (SyntaxContext, SyntaxKind::ClosureSignature);
2423
2426
if (Tok.is (tok::l_square) && peekToken ().is (tok::r_square)) {
2424
2427
@@ -2563,7 +2566,7 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2563
2566
if (pattern.isNonNull ())
2564
2567
params = pattern.get ();
2565
2568
else
2566
- invalid = true ;
2569
+ status. setIsParseError () ;
2567
2570
} else {
2568
2571
SyntaxParsingContext ClParamListCtx (SyntaxContext,
2569
2572
SyntaxKind::ClosureParamList);
@@ -2574,7 +2577,7 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2574
2577
SyntaxParsingContext ClParamCtx (SyntaxContext, SyntaxKind::ClosureParam);
2575
2578
if (Tok.isNot (tok::identifier, tok::kw__)) {
2576
2579
diagnose (Tok, diag::expected_closure_parameter_name);
2577
- invalid = true ;
2580
+ status. setIsParseError () ;
2578
2581
break ;
2579
2582
}
2580
2583
@@ -2598,8 +2601,8 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2598
2601
params = ParameterList::create (Context, elements);
2599
2602
}
2600
2603
2601
- parseEffectsSpecifiers (SourceLoc (), asyncLoc, throwsLoc,
2602
- /* rethrows*/ nullptr );
2604
+ status |= parseEffectsSpecifiers (SourceLoc (), asyncLoc, throwsLoc,
2605
+ /* rethrows*/ nullptr );
2603
2606
2604
2607
// Parse the optional explicit return type.
2605
2608
if (Tok.is (tok::arrow)) {
@@ -2613,7 +2616,7 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2613
2616
if (!explicitResultTypeRepr) {
2614
2617
// If we couldn't parse the result type, clear out the arrow location.
2615
2618
arrowLoc = SourceLoc ();
2616
- invalid = true ;
2619
+ status. setIsParseError () ;
2617
2620
} else {
2618
2621
explicitResultType = new (Context) TypeExpr (explicitResultTypeRepr);
2619
2622
}
@@ -2653,7 +2656,7 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2653
2656
}
2654
2657
2655
2658
if (!params)
2656
- return invalid ;
2659
+ return status ;
2657
2660
2658
2661
// If this was a closure declaration (maybe even trailing)
2659
2662
// tuple parameter destructuring is one of the common
@@ -2691,14 +2694,15 @@ parseClosureSignatureIfPresent(SourceRange &bracketRange,
2691
2694
.fixItReplace (param->getSourceRange (), argName)
2692
2695
.fixItInsert (Tok.getLoc (), OS.str ());
2693
2696
2694
- invalid = true ;
2697
+ status. setIsParseError () ;
2695
2698
}
2696
2699
2697
- return invalid ;
2700
+ return status ;
2698
2701
}
2699
2702
2700
2703
ParserResult<Expr> Parser::parseExprClosure () {
2701
2704
assert (Tok.is (tok::l_brace) && " Not at a left brace?" );
2705
+ ParserStatus Status;
2702
2706
SyntaxParsingContext ClosureContext (SyntaxContext, SyntaxKind::ClosureExpr);
2703
2707
// We may be parsing this closure expr in a matching pattern context. If so,
2704
2708
// reset our state to not be in a pattern for any recursive pattern parses.
@@ -2718,7 +2722,7 @@ ParserResult<Expr> Parser::parseExprClosure() {
2718
2722
SourceLoc arrowLoc;
2719
2723
TypeExpr *explicitResultType;
2720
2724
SourceLoc inLoc;
2721
- parseClosureSignatureIfPresent (
2725
+ Status |= parseClosureSignatureIfPresent (
2722
2726
bracketRange, captureList, capturedSelfDecl, params, asyncLoc, throwsLoc,
2723
2727
arrowLoc, explicitResultType, inLoc);
2724
2728
@@ -2753,7 +2757,6 @@ ParserResult<Expr> Parser::parseExprClosure() {
2753
2757
2754
2758
// Parse the body.
2755
2759
SmallVector<ASTNode, 4 > bodyElements;
2756
- ParserStatus Status;
2757
2760
Status |= parseBraceItems (bodyElements, BraceItemListKind::Brace);
2758
2761
2759
2762
if (SourceMgr.rangeContainsCodeCompletionLoc ({leftBrace, PreviousLoc})) {
0 commit comments