Skip to content

Commit d429d06

Browse files
committed
Don’t remove #if attributes with AttributeRemover
Fixes #2923 rdar://141840779
1 parent fd232f9 commit d429d06

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,11 @@ public class AttributeRemover: SyntaxRewriter {
530530

531531
public override func visit(_ node: AttributeListSyntax) -> AttributeListSyntax {
532532
var filteredAttributes: [AttributeListSyntax.Element] = []
533-
for case .attribute(let attribute) in node {
533+
for attribute in node {
534+
guard case .attribute(let attribute) = attribute else {
535+
filteredAttributes.append(attribute)
536+
continue
537+
}
534538
if self.predicate(attribute) {
535539
var leadingTrivia = attribute.leadingTrivia
536540

Tests/SwiftSyntaxMacroExpansionTest/AttributeRemoverTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,21 @@ final class AttributeRemoverTests: XCTestCase {
470470
"""
471471
)
472472
}
473+
474+
func testKeepPoundIfInAttributes() {
475+
assertSyntaxRemovingTestAttributes(
476+
"""
477+
#if true
478+
@inlinable
479+
#endif
480+
func f() {}
481+
""",
482+
reduction: """
483+
#if true
484+
@inlinable
485+
#endif
486+
func f() {}
487+
"""
488+
)
489+
}
473490
}

0 commit comments

Comments
 (0)