-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Diagnostics] Add a fix-it for try instead of throws in function decl… #27647
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
Conversation
@swift-ci please smoke test |
My bad! .. PR was not compiling. I pushed 59e8f20 with the fix. @CodaFi, could you pls trigger tests again? Thanks! |
@swift-ci please smoke test |
…s and types. Sometimes one would misstype `throws` for `try` so we provide a fix-it for that. It might happen in two cases: In function declarations: ```swift func foo() try {} ``` In function types: ```swift let f = () try -> Int ``` Resolves SR-11574.
Had to rebase due to revert of syxtax parsing swiftlang#27675.
@rintaro no worries. updated. |
lib/Parse/ParsePattern.cpp
Outdated
} else if (Tok.is(tok::kw_try)) { | ||
SourceLoc tryLoc = consumeToken(); | ||
diagnose(tryLoc, diag::throw_in_function_type) | ||
.fixItReplace(tryLoc, "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.
I think we should pretend that the throws
is correctly written. i.e. We should set throwsLoc
. Does just modifying the condition of the previous block to if (Tok.isAny(tok::kw_throw, kw_try))
work?
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.
yes, setting throwsLoc
does work. I pushed 9656057
@swift-ci Please smoke test |
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 Victor!
…s and types.
Sometimes one would misstype
throws
fortry
so we provide a fix-it for that.It might happen in two cases:
In function declarations:
In function types:
Resolves SR-11574.