Skip to content

[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

Merged
merged 3 commits into from
Jan 27, 2021

Conversation

etcwilde
Copy link
Member

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

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.
@etcwilde
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@etcwilde
Copy link
Member Author

@swift-ci please smoke test

@etcwilde etcwilde marked this pull request as draft January 26, 2021 23:03
@etcwilde
Copy link
Member Author

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".
@etcwilde
Copy link
Member Author

@swift-ci please smoke test

@etcwilde
Copy link
Member Author

It looks like the windows bot is full. The failure was: :0: note: IO failure on output stream: no space on device
https://ci-external.swift.org/job/swift-PR-windows/10264/console

@etcwilde etcwilde marked this pull request as ready for review January 27, 2021 04:16
Copy link
Contributor

@varungandhi-apple varungandhi-apple left a 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.
@etcwilde
Copy link
Member Author

@swift-ci please smoke test

@etcwilde
Copy link
Member Author

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.

Test case added. We get both diagnostics for fixing the async to await and the warning that puts the await after the try.
The fix-it for the warning will correct the positioning of the bad token and put an await in the right place, regardless of whether it was async or await.

@etcwilde
Copy link
Member Author

@swift-ci please smoke test windows platform

@etcwilde etcwilde merged commit 2c4f7b9 into swiftlang:main Jan 27, 2021
@etcwilde etcwilde deleted the ewilde/did-you-mean-await branch January 27, 2021 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants