@@ -2922,9 +2922,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2922
2922
// Parse the subject.
2923
2923
if (!Tok.isContextualKeyword (" set" )) {
2924
2924
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
+
2928
2926
if (Tok.is (tok::r_paren)) {
2929
2927
// Suggest `set` between empty parens e.g. `private()` -> `private(set)`
2930
2928
auto SetLoc = consumeToken (tok::r_paren);
@@ -2938,25 +2936,26 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
2938
2936
} else if (isNextStartOfSwiftDecl ()) {
2939
2937
// Suggest `set)` in place of an invalid token after l_paren followed by
2940
2938
// 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)" );
2943
2942
} else {
2944
2943
// 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> `
2946
2945
diag.fixItInsertAfter (LParenLoc, " set)" );
2947
2946
}
2948
-
2947
+
2949
2948
return makeParserSuccess ();
2950
2949
}
2951
-
2950
+
2952
2951
auto SubjectLoc = consumeToken ();
2953
2952
2954
2953
AttrRange = SourceRange (Loc, Tok.getLoc ());
2955
2954
2956
2955
if (!consumeIf (tok::r_paren)) {
2957
2956
diagnose (Loc, diag::attr_expected_rparen, AttrName,
2958
2957
DeclAttribute::isDeclModifier (DK))
2959
- .fixItInsertAfter (SubjectLoc, " )" );
2958
+ .fixItInsertAfter (SubjectLoc, " )" );
2960
2959
return makeParserSuccess ();
2961
2960
}
2962
2961
0 commit comments