[SE-0458] Drop "unsafe" effect for for..in loop in inlined code in interfaces

Only compilers can't handle it, so drop it for now.
This commit is contained in:
Doug Gregor
2025-02-26 22:03:49 -08:00
parent 983046f792
commit ae6ae33201
2 changed files with 15 additions and 0 deletions

View File

@@ -552,6 +552,10 @@ fileprivate class RemoveUnsafeExprSyntaxRewriter: SyntaxRewriter {
override func visit(_ node: UnsafeExprSyntax) -> ExprSyntax {
return node.expression.with(\.leadingTrivia, node.leadingTrivia)
}
override func visit(_ node: ForStmtSyntax) -> StmtSyntax {
return StmtSyntax(node.with(\.unsafeKeyword, nil))
}
}
extension SyntaxProtocol {

View File

@@ -9,10 +9,21 @@
// CHECK: #endif
@unsafe public func getIntUnsafely() -> Int { 0 }
public struct UnsafeIterator: @unsafe IteratorProtocol {
@unsafe public mutating func next() -> Int? { nil }
}
public struct SequenceWithUnsafeIterator: Sequence {
public init() { }
public func makeIterator() -> UnsafeIterator { UnsafeIterator() }
}
// CHECK: @inlinable public func useUnsafeCode()
@inlinable public func useUnsafeCode() {
// CHECK-NOT: unsafe
print( unsafe getIntUnsafely())
for unsafe _ in SequenceWithUnsafeIterator() { }
}
// CHECK: public protocol P