@MainActor
func iterate(over stream: AsyncStream<Int>) async {
for await ns in stream {
print(ns)
}
}
Building this code with -strict-concurrency=complete results in
warning: transferring '$ns$generator' may cause a race; this is an error in the Swift 6 language mode
4 | @MainActor
5 | func iterate(over stream: AsyncStream<Int>) async {
6 | for await ns in stream {
| |- warning: transferring '$ns$generator' may cause a race; this is an error in the Swift 6 language mode
| |- note: transferring disconnected '$ns$generator' to nonisolated callee could cause races in between callee nonisolated and local main actor-isolated uses
| `- note: use here could race
7 | print(ns)
8 | }
Description
No response
Reproduction
Building this code with
-strict-concurrency=complete
results inExpected behavior
No warning. The constraint system inserts
nonisolated(unsafe)
on the iterator variable to suppress this issue per https://github.com/apple/swift/pull/70697.Environment
Additional information
No response