New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Diagnostics] Add a fix-it for misplaced throws in function types #25306
[Diagnostics] Add a fix-it for misplaced throws in function types #25306
Conversation
@brentdax: This fixes the bug that you reported. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for picking this up! This implementation looks good but I do have a few notes.
lib/Parse/ParseType.cpp
Outdated
@@ -417,6 +417,12 @@ ParserResult<TypeRepr> Parser::parseType(Diag<> MessageID, | |||
if (Tok.is(tok::arrow)) { | |||
// Handle type-function if we have an arrow. | |||
SourceLoc arrowLoc = consumeToken(); | |||
if(Tok.is(tok::kw_throws)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Please put a space before the open-paren.
lib/Parse/ParseType.cpp
Outdated
if(Tok.is(tok::kw_throws)) { | ||
Diag<> DiagID = diag::throws_in_wrong_position; | ||
diagnose(Tok.getLoc(), DiagID).fixItInsert(arrowLoc, "throws ") | ||
.fixItRemove(Tok.getLoc()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a tab snuck in here.
lib/Parse/ParseType.cpp
Outdated
Diag<> DiagID = diag::throws_in_wrong_position; | ||
diagnose(Tok.getLoc(), DiagID).fixItInsert(arrowLoc, "throws ") | ||
.fixItRemove(Tok.getLoc()); | ||
consumeToken(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good, but I think we can probably recover as if the user wrote throws
in the correct place by setting throwsLoc
.
@swift-ci please smoke test |
@swift-ci Please smoke test |
Adds a diagnostic error for misplaced throws in function types. For e.g:
Resolves SR-10703.