mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Strict memory safety] Fix "unsafe" checking for the for..in loop
The `$generator` variable we create for the async for..in loop is `nonisolated(unsafe)`, so ensure that we generate an `unsafe` expression when we use it. This uncovered some inconsistencies in how we do `unsafe` checking for for..in loops, so fix those. Fixes rdar://154775389.
This commit is contained in:
@@ -98,6 +98,8 @@ func testUnsafeAsSequenceForEach() {
|
||||
for _ in unsafe uas { } // expected-warning{{for-in loop uses unsafe constructs but is not marked with 'unsafe'}}{{documentation-file=strict-memory-safety}}{{7-7=unsafe }}
|
||||
|
||||
for unsafe _ in unsafe uas { } // okay
|
||||
|
||||
for unsafe _ in [1, 2, 3] { } // expected-warning{{no unsafe operations occur within 'unsafe' for-in loop}}
|
||||
}
|
||||
|
||||
func testForInUnsafeAmbiguity(_ integers: [Int]) {
|
||||
|
||||
@@ -55,3 +55,10 @@ open class SyntaxVisitor {
|
||||
open class SyntaxAnyVisitor: SyntaxVisitor {
|
||||
override open func visit(_ token: TokenSyntax) { }
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.1, *)
|
||||
func testMemorySafetyWithForLoop() async {
|
||||
let (stream, continuation) = AsyncStream<Int>.makeStream()
|
||||
for await _ in stream {}
|
||||
_ = continuation
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user