@@ -2503,7 +2503,7 @@ static std::optional<Identifier> parseSingleAttrOptionImpl(
2503
2503
};
2504
2504
bool isDeclModifier = DeclAttribute::isDeclModifier (DK);
2505
2505
2506
- if (!P.Tok .is (tok::l_paren )) {
2506
+ if (!P.Tok .isFollowingLParen ( )) {
2507
2507
if (allowOmitted)
2508
2508
return Identifier ();
2509
2509
@@ -2883,7 +2883,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2883
2883
.Case (" public" , AccessLevel::Public)
2884
2884
.Case (" open" , AccessLevel::Open);
2885
2885
2886
- if (!Tok.is (tok::l_paren )) {
2886
+ if (!Tok.isFollowingLParen ( )) {
2887
2887
// Normal access control attribute.
2888
2888
AttrRange = Loc;
2889
2889
@@ -3458,7 +3458,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3458
3458
}
3459
3459
case DeclAttrKind::PrivateImport: {
3460
3460
// Parse the leading '('.
3461
- if (Tok.isNot (tok::l_paren )) {
3461
+ if (! Tok.isFollowingLParen ( )) {
3462
3462
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3463
3463
DeclAttribute::isDeclModifier (DK));
3464
3464
return makeParserSuccess ();
@@ -3507,7 +3507,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3507
3507
}
3508
3508
case DeclAttrKind::ObjC: {
3509
3509
// Unnamed @objc attribute.
3510
- if (Tok.isNot (tok::l_paren )) {
3510
+ if (! Tok.isFollowingLParen ( )) {
3511
3511
auto attr = ObjCAttr::createUnnamed (Context, AtLoc, Loc);
3512
3512
Attributes.add (attr);
3513
3513
break ;
@@ -3575,7 +3575,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3575
3575
3576
3576
case DeclAttrKind::DynamicReplacement: {
3577
3577
// Parse the leading '('.
3578
- if (Tok.isNot (tok::l_paren )) {
3578
+ if (! Tok.isFollowingLParen ( )) {
3579
3579
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3580
3580
DeclAttribute::isDeclModifier (DK));
3581
3581
return makeParserSuccess ();
@@ -3626,7 +3626,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3626
3626
3627
3627
case DeclAttrKind::TypeEraser: {
3628
3628
// Parse leading '('
3629
- if (Tok.isNot (tok::l_paren )) {
3629
+ if (! Tok.isFollowingLParen ( )) {
3630
3630
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3631
3631
DeclAttribute::isDeclModifier (DK));
3632
3632
return makeParserSuccess ();
@@ -3656,7 +3656,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3656
3656
3657
3657
case DeclAttrKind::Specialize:
3658
3658
case DeclAttrKind::Specialized: {
3659
- if (Tok.isNot (tok::l_paren )) {
3659
+ if (! Tok.isFollowingLParen ( )) {
3660
3660
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3661
3661
DeclAttribute::isDeclModifier (DK));
3662
3662
return makeParserSuccess ();
@@ -3885,7 +3885,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
3885
3885
break ;
3886
3886
}
3887
3887
case DeclAttrKind::RawLayout: {
3888
- if (Tok.isNot (tok::l_paren )) {
3888
+ if (! Tok.isFollowingLParen ( )) {
3889
3889
diagnose (Loc, diag::attr_expected_lparen, AttrName,
3890
3890
DeclAttribute::isDeclModifier (DK));
3891
3891
return makeParserSuccess ();
@@ -4187,7 +4187,7 @@ ParserResult<CustomAttr> Parser::parseCustomAttribute(SourceLoc atLoc) {
4187
4187
// Parse a custom attribute.
4188
4188
auto type = parseType (diag::expected_type, ParseTypeReason::CustomAttribute);
4189
4189
if (type.hasCodeCompletion () || type.isNull ()) {
4190
- if (Tok.is (tok::l_paren ) && isCustomAttributeArgument ())
4190
+ if (Tok.isFollowingLParen ( ) && isCustomAttributeArgument ())
4191
4191
skipSingle ();
4192
4192
4193
4193
return ParserResult<CustomAttr>(ParserStatus (type));
@@ -4369,7 +4369,7 @@ ParserStatus Parser::parseDeclAttribute(DeclAttributes &Attributes,
4369
4369
SourceLoc attrLoc = consumeToken ();
4370
4370
4371
4371
// @warn_unused_result with no arguments.
4372
- if (Tok.isNot (tok::l_paren )) {
4372
+ if (! Tok.isFollowingLParen ( )) {
4373
4373
diagnose (AtLoc, diag::attr_warn_unused_result_removed)
4374
4374
.fixItRemove (SourceRange (AtLoc, attrLoc));
4375
4375
@@ -4453,7 +4453,7 @@ ParserStatus Parser::parseDeclAttribute(DeclAttributes &Attributes,
4453
4453
4454
4454
// Recover by eating @foo(...) when foo is not known.
4455
4455
consumeToken ();
4456
- if (Tok.is (tok::l_paren ))
4456
+ if (Tok.isFollowingLParen ( ))
4457
4457
skipSingle ();
4458
4458
4459
4459
return makeParserError ();
@@ -5925,7 +5925,7 @@ bool Parser::isStartOfSwiftDecl(bool allowPoundIfAttributes,
5925
5925
// If it might be, we do some more digging.
5926
5926
5927
5927
// If this is 'unowned', check to see if it is valid.
5928
- if (Tok.getText () == " unowned" && Tok2.is (tok::l_paren )) {
5928
+ if (Tok.getText () == " unowned" && Tok2.isFollowingLParen ( )) {
5929
5929
Parser::BacktrackingScope Backtrack (*this );
5930
5930
if (consumeIfParenthesizedUnowned (*this )) {
5931
5931
return isStartOfSwiftDecl (/* allowPoundIfAttributes=*/ false ,
@@ -5934,7 +5934,7 @@ bool Parser::isStartOfSwiftDecl(bool allowPoundIfAttributes,
5934
5934
}
5935
5935
5936
5936
// If this is 'nonisolated', check to see if it is valid.
5937
- if (Tok.isContextualKeyword (" nonisolated" ) && Tok2.is (tok::l_paren )) {
5937
+ if (Tok.isContextualKeyword (" nonisolated" ) && Tok2.isFollowingLParen ( )) {
5938
5938
BacktrackingScope backtrack (*this );
5939
5939
if (consumeIfParenthesizedNonisolated (*this )) {
5940
5940
return isStartOfSwiftDecl (/* allowPoundIfAttributes=*/ false ,
@@ -7277,6 +7277,12 @@ ParserStatus Parser::parseDeclPoundDiagnostic() {
7277
7277
bool isError = Tok.is (tok::pound_error);
7278
7278
consumeToken (isError ? tok::pound_error : tok::pound_warning);
7279
7279
7280
+ if (Tok.isAtStartOfLine ()) {
7281
+ diagnose (Tok, diag::pound_diagnostic_expected_parens, isError)
7282
+ .fixItInsertAfter (PreviousLoc, " (\" <#message#>\" )" );
7283
+ return makeParserSuccess ();
7284
+ }
7285
+
7280
7286
SourceLoc lParenLoc = Tok.getLoc ();
7281
7287
bool hadLParen = consumeIf (tok::l_paren);
7282
7288
@@ -7373,7 +7379,7 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
7373
7379
7374
7380
unsigned StartLine = 0 ;
7375
7381
std::optional<StringRef> Filename;
7376
- if (!isLine) {
7382
+ if (!isLine && !Tok. isAtStartOfLine () ) {
7377
7383
// #sourceLocation()
7378
7384
// #sourceLocation(file: "foo", line: 42)
7379
7385
if (parseToken (tok::l_paren, diag::sourceLocation_expected, " (" ))
0 commit comments