Skip to content

[6.0] Fix missing break in nested IfConfig decls #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,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
}

Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}