Skip to content

[SR-13759] [Diag] Suggest inserting await when call is async #34509

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Sema/TypeCheckEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ class Context {
if (isAutoClosure())
diag = diag::async_call_without_await_in_autoclosure;
ctx.Diags.diagnose(node.getStartLoc(), diag)
.fixItInsert(node.getStartLoc(), "await ")
.highlight(highlight);
}

Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/objc_async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func testSlowServer(slowServer: SlowServer) async throws {

// still async version...
let _: Int = slowServer.doSomethingConflicted("thinking")
// expected-error@-1{{call is 'async' but is not marked with 'await'}}
// expected-error@-1{{call is 'async' but is not marked with 'await'}}{{16-16=await }}

let _: String? = await try slowServer.fortune()
let _: Int = await try slowServer.magicNumber(withSeed: 42)
Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func testOverloadedAsync() async {
let _: String? = await overloadedOptDifference() // no warning

let _ = await overloaded()
let _ = overloaded() // expected-error{{call is 'async' but is not marked with 'await'}}
let _ = overloaded() // expected-error{{call is 'async' but is not marked with 'await'}}{{11-11=await }}

let fn = {
overloaded()
Expand Down
8 changes: 4 additions & 4 deletions test/expr/unary/async_await.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func test1(asyncfp : () async -> Int, fp : () -> Int) async {
_ = await asyncfp() + asyncfp()
_ = await asyncfp() + fp()
_ = await fp() + 42 // expected-warning {{no calls to 'async' functions occur within 'await' expression}}
_ = asyncfp() // expected-error {{call is 'async' but is not marked with 'await'}}
_ = asyncfp() // expected-error {{call is 'async' but is not marked with 'await'}}{{7-7=await }}
}

func getInt() async -> Int { return 5 }
Expand Down Expand Up @@ -49,13 +49,13 @@ struct HasAsyncBad {
}

func testAutoclosure() async {
await acceptAutoclosureAsync(getInt()) // expected-error{{call is 'async' in an autoclosure argument that is not marked with 'await'}}
await acceptAutoclosureAsync(getInt()) // expected-error{{call is 'async' in an autoclosure argument that is not marked with 'await'}}{{32-32=await }}
await acceptAutoclosureNonAsync(getInt()) // expected-error{{'async' in an autoclosure that does not support concurrency}}

await acceptAutoclosureAsync(await getInt())
await acceptAutoclosureNonAsync(await getInt()) // expected-error{{'async' in an autoclosure that does not support concurrency}}

await acceptAutoclosureAsync(getInt()) // expected-error{{call is 'async' in an autoclosure argument that is not marked with 'await'}}
await acceptAutoclosureAsync(getInt()) // expected-error{{call is 'async' in an autoclosure argument that is not marked with 'await'}}{{32-32=await }}
await acceptAutoclosureNonAsync(getInt()) // expected-error{{'async' in an autoclosure that does not support concurrency}}
}

Expand Down Expand Up @@ -93,7 +93,7 @@ func testThrowingAndAsync() async throws {
// expected-note@-1{{did you mean to use 'try'?}}
// expected-note@-2{{did you mean to handle error as optional value?}}
// expected-note@-3{{did you mean to disable error propagation?}}
_ = try throwingAndAsync() // expected-error{{call is 'async' but is not marked with 'await'}}
_ = try throwingAndAsync() // expected-error{{call is 'async' but is not marked with 'await'}}{{11-11=await }}
}

func testExhaustiveDoCatch() async {
Expand Down