[Diagnostics] Improve diagnostics when passing async to a sync parameter

If `async` effect has been inferred from the body of the closure,
let's find out the first occurrence of `async` node and point it out
to make it clear why closure is `async`.

Resolves: rdar://70610141
This commit is contained in:
Pavel Yaskevich
2021-05-03 10:55:49 -07:00
parent 53992d04b6
commit 886a8ab6b7
4 changed files with 34 additions and 5 deletions

View File

@@ -33,9 +33,9 @@ func missingTryInBlock<T : AsyncSequence>(_ seq: T) {
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
func missingAsyncInBlock<T : AsyncSequence>(_ seq: T) {
execute { // expected-error{{invalid conversion from 'async' function of type '() async -> Void' to synchronous function type '() -> Void'}}
execute { // expected-error{{cannot pass function of type '() async -> Void' to parameter expecting synchronous function type}}
do {
for try await _ in seq { }
for try await _ in seq { } // expected-note {{'async' in a closure that does not support concurrency}}
} catch { }
}
}
@@ -81,4 +81,4 @@ func forAwaitWithConcreteType(_ seq: ThrowingAsyncSequence) throws { // expected
for try await elt in seq { // expected-error {{'async' in a function that does not support concurrency}}
_ = elt
}
}
}