Skip to content

Commit 6b33c66

Browse files
shawnhyamahoppen
authored andcommitted
Fix missing break in nested IfConfig decls. Fixes #779.
1 parent 53eae80 commit 6b33c66

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

+2
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,8 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
14531453
}
14541454

14551455
override func visit(_ node: IfConfigDeclSyntax) -> SyntaxVisitorContinueKind {
1456+
// there has to be a break after an #endif
1457+
after(node.poundEndif, tokens: .break(.same, size: 0))
14561458
return .visitChildren
14571459
}
14581460

Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift

+26
Original file line numberDiff line numberDiff line change
@@ -531,4 +531,30 @@ final class IfConfigTests: PrettyPrintTestCase {
531531
"""
532532
assertPrettyPrintEqual(input: input, expected: input, linelength: 45)
533533
}
534+
535+
func testNestedPoundIfInSwitchStatement() {
536+
let input =
537+
"""
538+
switch self {
539+
#if os(iOS) || os(tvOS) || os(watchOS)
540+
case .a:
541+
return 40
542+
#if os(iOS) || os(tvOS)
543+
case .e:
544+
return 30
545+
#endif
546+
#if os(iOS)
547+
case .g:
548+
return 2
549+
#endif
550+
#endif
551+
default:
552+
return nil
553+
}
554+
555+
"""
556+
var configuration = Configuration.forTesting
557+
configuration.indentConditionalCompilationBlocks = false
558+
assertPrettyPrintEqual(input: input, expected: input, linelength: 45, configuration: configuration)
559+
}
534560
}

0 commit comments

Comments
 (0)