mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SILGen verification crash when no other async functions are called in a function body not marked as async when a for-await-in syntax is used. This corrects the diagnostics to ensure that the type check effects sees the proper async call that the for-await-in syntax infers. for-await-in syntax was missing a diagnistic hint for inserting a try when the protocol conformance of the sequence shows a potential of throwing. (also there was a superfluous check for the nominal type in that type check (which was removed). for-await-in syntax and for-try-await-in syntax did not infer async or throwing to closure constraints, both were added to properly identify the asyncy-ness/throwy-ness of the iteration.
34 lines
1.3 KiB
Swift
34 lines
1.3 KiB
Swift
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
|
|
// REQUIRES: concurrency
|
|
|
|
// expected-note@+1{{add 'async' to function 'missingAsync' to make it asynchronous}}
|
|
func missingAsync<T : AsyncSequence>(_ seq: T) throws {
|
|
for try await _ in seq { } // expected-error{{'async' in a function that does not support concurrency}}
|
|
}
|
|
|
|
func missingThrows<T : AsyncSequence>(_ seq: T) async {
|
|
for try await _ in seq { } // expected-error{{error is not handled because the enclosing function is not declared 'throws'}}
|
|
}
|
|
|
|
func executeAsync(_ work: () async -> Void) { }
|
|
func execute(_ work: () -> Void) { }
|
|
|
|
func missingThrowingInBlock<T : AsyncSequence>(_ seq: T) {
|
|
executeAsync { // expected-error{{invalid conversion from throwing function of type '() async throws -> Void' to non-throwing function type '() async -> Void'}}
|
|
for try await _ in seq { }
|
|
}
|
|
}
|
|
|
|
func missingTryInBlock<T : AsyncSequence>(_ seq: T) {
|
|
executeAsync {
|
|
for await _ in seq { } // expected-error{{call can throw, but the error is not handled}}
|
|
}
|
|
}
|
|
|
|
func missingAsyncInBlock<T : AsyncSequence>(_ seq: T) {
|
|
execute { // expected-error{{invalid conversion from 'async' function of type '() async -> Void' to synchronous function type '() -> Void'}}
|
|
do {
|
|
for try await _ in seq { }
|
|
} catch { }
|
|
}
|
|
} |