diff --git a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift index a697c0e3..a2f6ccdf 100644 --- a/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift +++ b/Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift @@ -1459,6 +1459,8 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor { } override func visit(_ node: IfConfigDeclSyntax) -> SyntaxVisitorContinueKind { + // there has to be a break after an #endif + after(node.poundEndif, tokens: .break(.same, size: 0)) return .visitChildren } diff --git a/Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift b/Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift index 5a611352..4f4a85b3 100644 --- a/Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift +++ b/Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift @@ -531,4 +531,30 @@ final class IfConfigTests: PrettyPrintTestCase { """ assertPrettyPrintEqual(input: input, expected: input, linelength: 45) } + + func testNestedPoundIfInSwitchStatement() { + let input = + """ + switch self { + #if os(iOS) || os(tvOS) || os(watchOS) + case .a: + return 40 + #if os(iOS) || os(tvOS) + case .e: + return 30 + #endif + #if os(iOS) + case .g: + return 2 + #endif + #endif + default: + return nil + } + + """ + var configuration = Configuration.forTesting + configuration.indentConditionalCompilationBlocks = false + assertPrettyPrintEqual(input: input, expected: input, linelength: 45, configuration: configuration) + } }