Skip to content

Commit 15d566d

Browse files
authored
SR-13759: FixIt - Insert await on async (#34509)
1 parent 6c46841 commit 15d566d

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,7 @@ class Context {
12381238
if (isAutoClosure())
12391239
diag = diag::async_call_without_await_in_autoclosure;
12401240
ctx.Diags.diagnose(node.getStartLoc(), diag)
1241+
.fixItInsert(node.getStartLoc(), "await ")
12411242
.highlight(highlight);
12421243
}
12431244

test/ClangImporter/objc_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func testSlowServer(slowServer: SlowServer) async throws {
1818

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

2323
let _: String? = await try slowServer.fortune()
2424
let _: Int = await try slowServer.magicNumber(withSeed: 42)

test/Constraints/async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func testOverloadedAsync() async {
5959
let _: String? = await overloadedOptDifference() // no warning
6060

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

6464
let fn = {
6565
overloaded()

test/expr/unary/async_await.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func test1(asyncfp : () async -> Int, fp : () -> Int) async {
77
_ = await asyncfp() + asyncfp()
88
_ = await asyncfp() + fp()
99
_ = await fp() + 42 // expected-warning {{no calls to 'async' functions occur within 'await' expression}}
10-
_ = asyncfp() // expected-error {{call is 'async' but is not marked with 'await'}}
10+
_ = asyncfp() // expected-error {{call is 'async' but is not marked with 'await'}}{{7-7=await }}
1111
}
1212

1313
func getInt() async -> Int { return 5 }
@@ -49,13 +49,13 @@ struct HasAsyncBad {
4949
}
5050

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

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

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

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

9999
func testExhaustiveDoCatch() async {

0 commit comments

Comments
 (0)