-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest replacing 'async' with 'await' at call site
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.
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency -parse-as-library | ||
// REQUIRES: concurrency | ||
|
||
func asyncFunc() async throws {} | ||
|
||
func anotherAsyncFunc() async -> Int { | ||
return 42 | ||
} | ||
|
||
@main struct MyProgram { | ||
static func main() async throws { | ||
// expected-error@+7 {{cannot find 'async' in scope; did you mean 'await'?}}{{9-14=await}} | ||
// expected-error@+6 {{consecutive statements on a line must be separated by ';'}} | ||
// expected-error@+5 {{call is 'async' but is not marked with 'await'}} | ||
// expected-error@+4 {{call can throw but is not marked with 'try'}} | ||
// expected-note@+3 {{did you mean to use 'try'?}} | ||
// expected-note@+2 {{did you mean to handle error as optional value?}} | ||
// expected-note@+1 {{did you mean to disable error propagation?}} | ||
try async asyncFunc() | ||
|
||
// expected-error@+4 {{consecutive statements on a line must be separated by ';'}} | ||
// expected-error@+3 {{cannot find 'async' in scope; did you mean 'await'?}}{{13-18=await}} | ||
// expected-warning@+2 {{result of call to 'anotherAsyncFunc()' is unused}} | ||
// expected-error@+1 {{call is 'async' but is not marked with 'await'}} | ||
let _ = async anotherAsyncFunc() | ||
|
||
// Don't emit a diagnostic here | ||
async let foo = anotherAsyncFunc() | ||
let _ = await foo | ||
} | ||
} |