Skip to content

Commit 58f07e3

Browse files
authored
Merge pull request #782 from ahoppen/6.0/fix-nested-if-config-statements
[6.0] Fix missing break in nested IfConfig decls
2 parents 50884c3 + 6b33c66 commit 58f07e3

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
@@ -1459,6 +1459,8 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
14591459
}
14601460

14611461
override func visit(_ node: IfConfigDeclSyntax) -> SyntaxVisitorContinueKind {
1462+
// there has to be a break after an #endif
1463+
after(node.poundEndif, tokens: .break(.same, size: 0))
14621464
return .visitChildren
14631465
}
14641466

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)