@@ -2033,13 +2033,20 @@ static AttrOptionSwitch<R>
20332033parseSingleAttrOption (Parser &P, SourceLoc Loc, SourceRange &AttrRange,
20342034 StringRef AttrName, DeclAttrKind DK) {
20352035 bool isModifier = DeclAttribute::isDeclModifier (DK);
2036- if (!P.consumeIf (tok::l_paren)) {
2036+ if (!P.Tok . is (tok::l_paren)) {
20372037 AttrRange = SourceRange (Loc);
20382038 // Create an AttrOptionSwitch with an empty value. The calls on it will
20392039 // decide whether or not that's valid.
20402040 return AttrOptionSwitch<R>(StringRef (), P, Loc, AttrName, isModifier);
20412041 }
20422042
2043+ llvm::Optional<SyntaxParsingContext> ModDetailContext;
2044+ if (DK == DAK_ReferenceOwnership) {
2045+ ModDetailContext.emplace (P.SyntaxContext , SyntaxKind::DeclModifierDetail);
2046+ }
2047+
2048+ P.consumeToken (tok::l_paren);
2049+
20432050 StringRef parsedName = P.Tok .getText ();
20442051 if (!P.consumeIf (tok::identifier)) {
20452052 // Once we have an example of a valid option, diagnose this with
@@ -2288,7 +2295,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
22882295 .Case (" public" , AccessLevel::Public)
22892296 .Case (" open" , AccessLevel::Open);
22902297
2291- if (!consumeIf (tok::l_paren)) {
2298+ if (!Tok. is (tok::l_paren)) {
22922299 // Normal access control attribute.
22932300 AttrRange = Loc;
22942301 DuplicateAttribute = Attributes.getAttribute <AccessControlAttr>();
@@ -2297,6 +2304,11 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
22972304 break ;
22982305 }
22992306
2307+ SyntaxParsingContext ModDetailContext (
2308+ SyntaxContext, SyntaxKind::DeclModifierDetail);
2309+
2310+ consumeToken (tok::l_paren);
2311+
23002312 // Parse the subject.
23012313 if (Tok.isContextualKeyword (" set" )) {
23022314 consumeToken ();
@@ -4723,7 +4735,7 @@ Parser::parseDecl(ParseDeclOptions Flags,
47234735
47244736 if (Tok.isContextualKeyword (" actor" ) && peekToken ().is (tok::identifier)) {
47254737 Tok.setKind (tok::contextual_keyword);
4726- DeclParsingContext.setCreateSyntax (SyntaxKind::ClassDecl );
4738+ DeclParsingContext.setCreateSyntax (SyntaxKind::ActorDecl );
47274739 DeclResult = parseDeclClass (Flags, Attributes);
47284740 break ;
47294741 }
@@ -8395,13 +8407,20 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
83958407 return Status;
83968408 }
83978409
8398- // Parse the parameters.
83998410 DefaultArgumentInfo DefaultArgs;
8400- llvm::SmallVector<Identifier, 4 > namePieces;
8401- ParserResult<ParameterList> Params
8402- = parseSingleParameterClause (ParameterContextKind::Initializer,
8403- &namePieces, &DefaultArgs);
8404- Status |= Params;
8411+ TypeRepr *FuncRetTy = nullptr ;
8412+ DeclName FullName;
8413+ ParameterList *BodyParams;
8414+ SourceLoc asyncLoc;
8415+ bool reasync;
8416+ SourceLoc throwsLoc;
8417+ bool rethrows;
8418+ Status |= parseFunctionSignature (DeclBaseName::createConstructor (), FullName,
8419+ BodyParams,
8420+ DefaultArgs,
8421+ asyncLoc, reasync,
8422+ throwsLoc, rethrows,
8423+ FuncRetTy);
84058424 if (Status.hasCodeCompletion () && !CodeCompletion) {
84068425 // Trigger delayed parsing, no need to continue.
84078426 return Status;
@@ -8413,17 +8432,23 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
84138432 return nullptr ;
84148433 }
84158434
8416- // Parse 'async' / 'reasync' / 'throws' / 'rethrows'.
8417- SourceLoc asyncLoc;
8418- bool reasync = false ;
8419- SourceLoc throwsLoc;
8420- bool rethrows = false ;
8421- Status |= parseEffectsSpecifiers (SourceLoc (),
8422- asyncLoc, &reasync,
8423- throwsLoc, &rethrows);
8424- if (Status.hasCodeCompletion () && !CodeCompletion) {
8425- // Trigger delayed parsing, no need to continue.
8426- return Status;
8435+ // If there was an 'async' modifier, put it in the right place for an
8436+ // initializer.
8437+ bool isAsync = asyncLoc.isValid ();
8438+ if (auto asyncAttr = Attributes.getAttribute <AsyncAttr>()) {
8439+ SourceLoc insertLoc = Lexer::getLocForEndOfToken (
8440+ SourceMgr, BodyParams->getRParenLoc ());
8441+
8442+ diagnose (asyncAttr->getLocation (), diag::async_func_modifier)
8443+ .fixItRemove (asyncAttr->getRange ())
8444+ .fixItInsert (insertLoc, " async" );
8445+ asyncAttr->setInvalid ();
8446+ isAsync = true ;
8447+ }
8448+
8449+ if (FuncRetTy) {
8450+ diagnose (FuncRetTy->getStartLoc (), diag::initializer_result_type)
8451+ .fixItRemove (FuncRetTy->getSourceRange ());
84278452 }
84288453
84298454 if (reasync) {
@@ -8435,12 +8460,11 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
84358460
84368461 diagnoseWhereClauseInGenericParamList (GenericParams);
84378462
8438- DeclName FullName (Context, DeclBaseName::createConstructor (), namePieces);
84398463 auto *CD = new (Context) ConstructorDecl (FullName, ConstructorLoc,
84408464 Failable, FailabilityLoc,
8441- asyncLoc. isValid () , asyncLoc,
8465+ isAsync , asyncLoc,
84428466 throwsLoc.isValid (), throwsLoc,
8443- Params. get () , GenericParams,
8467+ BodyParams , GenericParams,
84448468 CurDeclContext);
84458469 CD->setImplicitlyUnwrappedOptional (IUO);
84468470 CD->getAttrs () = Attributes;
@@ -8466,7 +8490,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
84668490 CodeCompletion->setParsedDecl (CD);
84678491 }
84688492
8469- if (ConstructorsNotAllowed || Params. isParseErrorOrHasCompletion () ) {
8493+ if (ConstructorsNotAllowed) {
84708494 // Tell the type checker not to touch this constructor.
84718495 CD->setInvalid ();
84728496 }
0 commit comments