Skip to content

Commit ae6ae33

Browse files
committed
[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.
1 parent 983046f commit ae6ae33

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/ASTGen/Sources/ASTGen/CompilerBuildConfiguration.swift

+4
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,10 @@ fileprivate class RemoveUnsafeExprSyntaxRewriter: SyntaxRewriter {
552552
override func visit(_ node: UnsafeExprSyntax) -> ExprSyntax {
553553
return node.expression.with(\.leadingTrivia, node.leadingTrivia)
554554
}
555+
556+
override func visit(_ node: ForStmtSyntax) -> StmtSyntax {
557+
return StmtSyntax(node.with(\.unsafeKeyword, nil))
558+
}
555559
}
556560

557561
extension SyntaxProtocol {

test/Unsafe/module-interface.swift

+11
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,21 @@
99
// CHECK: #endif
1010
@unsafe public func getIntUnsafely() -> Int { 0 }
1111

12+
public struct UnsafeIterator: @unsafe IteratorProtocol {
13+
@unsafe public mutating func next() -> Int? { nil }
14+
}
15+
16+
public struct SequenceWithUnsafeIterator: Sequence {
17+
public init() { }
18+
public func makeIterator() -> UnsafeIterator { UnsafeIterator() }
19+
}
20+
1221
// CHECK: @inlinable public func useUnsafeCode()
1322
@inlinable public func useUnsafeCode() {
1423
// CHECK-NOT: unsafe
1524
print( unsafe getIntUnsafely())
25+
26+
for unsafe _ in SequenceWithUnsafeIterator() { }
1627
}
1728

1829
// CHECK: public protocol P

0 commit comments

Comments
 (0)