16
16
17
17
#include " swift/Parse/Parser.h"
18
18
#include " swift/AST/ASTWalker.h"
19
+ #include " swift/AST/Attr.h"
19
20
#include " swift/AST/DiagnosticsParse.h"
20
21
#include " swift/AST/TypeRepr.h"
21
22
#include " swift/Basic/EditorPlaceholder.h"
@@ -2335,6 +2336,7 @@ static void printTupleNames(const TypeRepr *typeRepr, llvm::raw_ostream &OS) {
2335
2336
}
2336
2337
2337
2338
ParserStatus Parser::parseClosureSignatureIfPresent (
2339
+ DeclAttributes &attributes,
2338
2340
SourceRange &bracketRange,
2339
2341
SmallVectorImpl<CaptureListEntry> &captureList,
2340
2342
VarDecl *&capturedSelfDecl,
@@ -2344,6 +2346,7 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2344
2346
TypeExpr *&explicitResultType, SourceLoc &inLoc) {
2345
2347
// Clear out result parameters.
2346
2348
bracketRange = SourceRange ();
2349
+ attributes = DeclAttributes ();
2347
2350
capturedSelfDecl = nullptr ;
2348
2351
params = nullptr ;
2349
2352
throwsLoc = SourceLoc ();
@@ -2360,9 +2363,16 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2360
2363
2361
2364
// If we have a leading token that may be part of the closure signature, do a
2362
2365
// speculative parse to validate it and look for 'in'.
2363
- if (Tok.isAny (tok::l_paren, tok::l_square, tok::identifier, tok::kw__)) {
2366
+ if (Tok.isAny (
2367
+ tok::at_sign, tok::l_paren, tok::l_square, tok::identifier,
2368
+ tok::kw__)) {
2364
2369
BacktrackingScope backtrack (*this );
2365
2370
2371
+ // Consume attributes.
2372
+ while (Tok.is (tok::at_sign)) {
2373
+ skipAnyAttribute ();
2374
+ }
2375
+
2366
2376
// Skip by a closure capture list if present.
2367
2377
if (consumeIf (tok::l_square)) {
2368
2378
skipUntil (tok::r_square);
@@ -2425,6 +2435,9 @@ ParserStatus Parser::parseClosureSignatureIfPresent(
2425
2435
}
2426
2436
ParserStatus status;
2427
2437
SyntaxParsingContext ClosureSigCtx (SyntaxContext, SyntaxKind::ClosureSignature);
2438
+
2439
+ (void )parseDeclAttributeList (attributes);
2440
+
2428
2441
if (Tok.is (tok::l_square) && peekToken ().is (tok::r_square)) {
2429
2442
2430
2443
SyntaxParsingContext CaptureCtx (SyntaxContext,
@@ -2721,6 +2734,7 @@ ParserResult<Expr> Parser::parseExprClosure() {
2721
2734
SourceLoc leftBrace = consumeToken ();
2722
2735
2723
2736
// Parse the closure-signature, if present.
2737
+ DeclAttributes attributes;
2724
2738
SourceRange bracketRange;
2725
2739
SmallVector<CaptureListEntry, 2 > captureList;
2726
2740
VarDecl *capturedSelfDecl;
@@ -2731,8 +2745,8 @@ ParserResult<Expr> Parser::parseExprClosure() {
2731
2745
TypeExpr *explicitResultType;
2732
2746
SourceLoc inLoc;
2733
2747
Status |= parseClosureSignatureIfPresent (
2734
- bracketRange, captureList, capturedSelfDecl, params, asyncLoc, throwsLoc ,
2735
- arrowLoc, explicitResultType, inLoc);
2748
+ attributes, bracketRange, captureList, capturedSelfDecl, params, asyncLoc,
2749
+ throwsLoc, arrowLoc, explicitResultType, inLoc);
2736
2750
2737
2751
// If the closure was created in the context of an array type signature's
2738
2752
// size expression, there will not be a local context. A parse error will
@@ -2748,8 +2762,8 @@ ParserResult<Expr> Parser::parseExprClosure() {
2748
2762
2749
2763
// Create the closure expression and enter its context.
2750
2764
auto *closure = new (Context) ClosureExpr (
2751
- bracketRange, capturedSelfDecl, params, asyncLoc, throwsLoc, arrowLoc ,
2752
- inLoc, explicitResultType, discriminator, CurDeclContext);
2765
+ attributes, bracketRange, capturedSelfDecl, params, asyncLoc, throwsLoc,
2766
+ arrowLoc, inLoc, explicitResultType, discriminator, CurDeclContext);
2753
2767
ParseFunctionBody cc (*this , closure);
2754
2768
2755
2769
// Handle parameters.
0 commit comments