@@ -2922,9 +2922,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
29222922 // Parse the subject.
29232923 if (!Tok.isContextualKeyword (" set" )) {
29242924 auto diag = diagnose (Loc, diag::attr_access_expected_set, AttrName);
2925-
2926- // Minimal recovery: if there's a single token and then an r_paren,
2927- // consume them both. If there's just an r_paren, consume that.
2925+
29282926 if (Tok.is (tok::r_paren)) {
29292927 // Suggest `set` between empty parens e.g. `private()` -> `private(set)`
29302928 auto SetLoc = consumeToken (tok::r_paren);
@@ -2938,25 +2936,26 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
29382936 } else if (isNextStartOfSwiftDecl ()) {
29392937 // Suggest `set)` in place of an invalid token after l_paren followed by
29402938 // a valid declaration start.
2941- // e.g. `private( var x: Int` -> `private(set) var x: Int`
2942- diag.fixItReplace (Tok.getLoc (), " set)" );
2939+ // e.g. `private(<invalid> var x: Int` -> `private(set) var x: Int`
2940+ auto SetLoc = consumeToken ();
2941+ diag.fixItReplace (SetLoc, " set)" );
29432942 } else {
29442943 // Suggest `set)` after l_paren if not followed by a valid declaration
2945- // e.g. `private( val x: Int ` -> `private(set) val x: Int `
2944+ // e.g. `private( <invalid> ` -> `private(set) <invalid> `
29462945 diag.fixItInsertAfter (LParenLoc, " set)" );
29472946 }
2948-
2947+
29492948 return makeParserSuccess ();
29502949 }
2951-
2950+
29522951 auto SubjectLoc = consumeToken ();
29532952
29542953 AttrRange = SourceRange (Loc, Tok.getLoc ());
29552954
29562955 if (!consumeIf (tok::r_paren)) {
29572956 diagnose (Loc, diag::attr_expected_rparen, AttrName,
29582957 DeclAttribute::isDeclModifier (DK))
2959- .fixItInsertAfter (SubjectLoc, " )" );
2958+ .fixItInsertAfter (SubjectLoc, " )" );
29602959 return makeParserSuccess ();
29612960 }
29622961
0 commit comments