@@ -8395,13 +8395,20 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
8395
8395
return Status;
8396
8396
}
8397
8397
8398
- // Parse the parameters.
8399
8398
DefaultArgumentInfo DefaultArgs;
8400
- llvm::SmallVector<Identifier, 4 > namePieces;
8401
- ParserResult<ParameterList> Params
8402
- = parseSingleParameterClause (ParameterContextKind::Initializer,
8403
- &namePieces, &DefaultArgs);
8404
- Status |= Params;
8399
+ TypeRepr *FuncRetTy = nullptr ;
8400
+ DeclName FullName;
8401
+ ParameterList *BodyParams;
8402
+ SourceLoc asyncLoc;
8403
+ bool reasync;
8404
+ SourceLoc throwsLoc;
8405
+ bool rethrows;
8406
+ Status |= parseFunctionSignature (DeclBaseName::createConstructor (), FullName,
8407
+ BodyParams,
8408
+ DefaultArgs,
8409
+ asyncLoc, reasync,
8410
+ throwsLoc, rethrows,
8411
+ FuncRetTy);
8405
8412
if (Status.hasCodeCompletion () && !CodeCompletion) {
8406
8413
// Trigger delayed parsing, no need to continue.
8407
8414
return Status;
@@ -8413,17 +8420,23 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
8413
8420
return nullptr ;
8414
8421
}
8415
8422
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;
8423
+ // If there was an 'async' modifier, put it in the right place for an
8424
+ // initializer.
8425
+ bool isAsync = asyncLoc.isValid ();
8426
+ if (auto asyncAttr = Attributes.getAttribute <AsyncAttr>()) {
8427
+ SourceLoc insertLoc = Lexer::getLocForEndOfToken (
8428
+ SourceMgr, BodyParams->getRParenLoc ());
8429
+
8430
+ diagnose (asyncAttr->getLocation (), diag::async_func_modifier)
8431
+ .fixItRemove (asyncAttr->getRange ())
8432
+ .fixItInsert (insertLoc, " async" );
8433
+ asyncAttr->setInvalid ();
8434
+ isAsync = true ;
8435
+ }
8436
+
8437
+ if (FuncRetTy) {
8438
+ diagnose (FuncRetTy->getStartLoc (), diag::initializer_result_type)
8439
+ .fixItRemove (FuncRetTy->getSourceRange ());
8427
8440
}
8428
8441
8429
8442
if (reasync) {
@@ -8435,12 +8448,11 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
8435
8448
8436
8449
diagnoseWhereClauseInGenericParamList (GenericParams);
8437
8450
8438
- DeclName FullName (Context, DeclBaseName::createConstructor (), namePieces);
8439
8451
auto *CD = new (Context) ConstructorDecl (FullName, ConstructorLoc,
8440
8452
Failable, FailabilityLoc,
8441
- asyncLoc. isValid () , asyncLoc,
8453
+ isAsync , asyncLoc,
8442
8454
throwsLoc.isValid (), throwsLoc,
8443
- Params. get () , GenericParams,
8455
+ BodyParams , GenericParams,
8444
8456
CurDeclContext);
8445
8457
CD->setImplicitlyUnwrappedOptional (IUO);
8446
8458
CD->getAttrs () = Attributes;
@@ -8466,7 +8478,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
8466
8478
CodeCompletion->setParsedDecl (CD);
8467
8479
}
8468
8480
8469
- if (ConstructorsNotAllowed || Params. isParseErrorOrHasCompletion () ) {
8481
+ if (ConstructorsNotAllowed) {
8470
8482
// Tell the type checker not to touch this constructor.
8471
8483
CD->setInvalid ();
8472
8484
}
0 commit comments