@@ -4331,6 +4331,21 @@ parseIdentifierDeclName(Parser &P, Identifier &Result, SourceLoc &Loc,
4331
4331
return makeParserError ();
4332
4332
}
4333
4333
4334
+ // If there is expected tokens after the code completion token, just eat the
4335
+ // code completion token. We don't need code completion here.
4336
+ // E.g.:
4337
+ // 'func' <completion> ('('|'<')
4338
+ // 'typealias' <completion> ('='|'<')
4339
+ // If there's no expected token after the completion, override completion may
4340
+ // kicks in. So leave the token here.
4341
+ // E.g.
4342
+ // 'func' <completion>
4343
+ // 'init' <completion>
4344
+ if (P.Tok .is (tok::code_complete) && canRecover (P.peekToken ())) {
4345
+ P.consumeToken (tok::code_complete);
4346
+ return makeParserCodeCompletionStatus ();
4347
+ }
4348
+
4334
4349
P.diagnose (P.Tok , diag::expected_identifier_in_decl, DeclKindName);
4335
4350
return makeParserError ();
4336
4351
}
@@ -4882,7 +4897,7 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
4882
4897
[](const Token &next) { return next.isAny (tok::colon, tok::equal); });
4883
4898
if (Status.isError ()) {
4884
4899
TmpCtxt->setTransparent ();
4885
- return nullptr ;
4900
+ return Status ;
4886
4901
}
4887
4902
4888
4903
DebuggerContextChange DCC (*this , Id, DeclKind::TypeAlias);
@@ -4998,8 +5013,8 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
4998
5013
*this , Id, IdLoc, " associatedtype" ,
4999
5014
[](const Token &next) { return next.isAny (tok::colon, tok::equal); });
5000
5015
if (Status.isError ())
5001
- return nullptr ;
5002
-
5016
+ return Status ;
5017
+
5003
5018
DebuggerContextChange DCC (*this , Id, DeclKind::AssociatedType);
5004
5019
5005
5020
// Reject generic parameters with a specific error.
@@ -6237,7 +6252,7 @@ ParserResult<FuncDecl> Parser::parseDeclFunc(SourceLoc StaticLoc,
6237
6252
startsWithLess (next);
6238
6253
});
6239
6254
if (NameStatus.isError ())
6240
- return nullptr ;
6255
+ return NameStatus ;
6241
6256
}
6242
6257
6243
6258
DebuggerContextChange DCC (*this , SimpleName, DeclKind::Func);
@@ -6510,7 +6525,7 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
6510
6525
return next.isAny (tok::colon, tok::l_brace) || startsWithLess (next);
6511
6526
});
6512
6527
if (Status.isError ())
6513
- return nullptr ;
6528
+ return Status ;
6514
6529
6515
6530
DebuggerContextChange DCC (*this , EnumName, DeclKind::Enum);
6516
6531
@@ -6792,7 +6807,7 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
6792
6807
return next.isAny (tok::colon, tok::l_brace) || startsWithLess (next);
6793
6808
});
6794
6809
if (Status.isError ())
6795
- return nullptr ;
6810
+ return Status ;
6796
6811
6797
6812
DebuggerContextChange DCC (*this , StructName, DeclKind::Struct);
6798
6813
@@ -6885,7 +6900,7 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
6885
6900
return next.isAny (tok::colon, tok::l_brace) || startsWithLess (next);
6886
6901
});
6887
6902
if (Status.isError ())
6888
- return nullptr ;
6903
+ return Status ;
6889
6904
6890
6905
DebuggerContextChange DCC (*this , ClassName, DeclKind::Class);
6891
6906
@@ -7005,7 +7020,7 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
7005
7020
*this , ProtocolName, NameLoc, " protocol" ,
7006
7021
[&](const Token &next) { return next.isAny (tok::colon, tok::l_brace); });
7007
7022
if (Status.isError ())
7008
- return nullptr ;
7023
+ return Status ;
7009
7024
7010
7025
// Protocols don't support generic parameters, but people often want them and
7011
7026
// we want to have good error recovery if they try them out. Parse them and
0 commit comments