Skip to content

Commit 1b2fad1

Browse files
committed
Properly recurse when removing "unsafe" from inlinable code
I forgot that I have to manually recurse in the syntactic rewriter. Do so. Fixes rdar://147877042
1 parent a95785c commit 1b2fad1

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/ASTGen/Sources/ASTGen/CompilerBuildConfiguration.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,11 +550,13 @@ public func extractInlinableText(
550550
/// a syntax tree.
551551
fileprivate class RemoveUnsafeExprSyntaxRewriter: SyntaxRewriter {
552552
override func visit(_ node: UnsafeExprSyntax) -> ExprSyntax {
553-
return node.expression.with(\.leadingTrivia, node.leadingTrivia)
553+
let rewritten = super.visit(node).cast(UnsafeExprSyntax.self)
554+
return rewritten.expression.with(\.leadingTrivia, node.leadingTrivia)
554555
}
555556

556557
override func visit(_ node: ForStmtSyntax) -> StmtSyntax {
557-
return StmtSyntax(node.with(\.unsafeKeyword, nil))
558+
let rewritten = super.visit(node).cast(ForStmtSyntax.self)
559+
return StmtSyntax(rewritten.with(\.unsafeKeyword, nil))
558560
}
559561
}
560562

test/Unsafe/module-interface.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public struct SequenceWithUnsafeIterator: Sequence {
2323
// CHECK-NOT: unsafe
2424
print( unsafe getIntUnsafely())
2525

26-
for unsafe _ in SequenceWithUnsafeIterator() { }
26+
for unsafe _ in SequenceWithUnsafeIterator() {
27+
_ = unsafe getIntUnsafely()
28+
}
2729
}
2830

2931
// CHECK: public protocol P

0 commit comments

Comments
 (0)