-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Concurrency] Suggest replacing 'async' with 'await' at call site #35518
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
It's pretty easy to typo-replace 'await' with 'async' and get a confusing error about 'async' not being in scope. This patch updates the diagnostic to suggest replacing 'async' with 'await' at the call-sites so that users aren't left scratching their heads.
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
I'm going to emit the error in the parser, fix the AST there, and then we should be able to continue compilation without emitting the confusing errors. |
By replacing the 'async' with 'await' in the parser, we avoid the issue of cascading errors as the compiler gets more and more confused by what it's reading. Instead, everything mostly passes and we just emit the one error message. One caveat that I hadn't taken into account before was that we could have a function called "async", in which case we don't want to replace the "async" keyword with "await".
@swift-ci please smoke test |
It looks like the windows bot is full. The failure was: :0: note: IO failure on output stream: no space on device |
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.
Mostly LGTM. It would be nice to add a test case for async try
(adapting the code if needed to correct it to try await
), but it's less important and would be okay as a smaller JIRA task that someone else can pick up.
Ensure that we emit the proper diagnostics for when the await and try are flipped, but also await is incorrectly spelled `async`. We're expecting two diagnostics, both of which have fix-its that do the right thing. One will just replace the `async` with an `await`. The other will move the text so that try comes first. Because `await` and `async` are both have the same number of characters, both fix-its will fix the issue correctly.
@swift-ci please smoke test |
Test case added. We get both diagnostics for fixing the |
@swift-ci please smoke test windows platform |
It's pretty easy to typo-replace 'await' with 'async' and get a
confusing error about 'async' not being in scope. This patch updates the
diagnostic to suggest replacing 'async' with 'await' at the call-sites
so that users aren't left scratching their heads.
Fixes: rdar://72968205