Skip to content

Commit 53238b5

Browse files
committed
Make sure there is a break after an #endif.
You wouldn't normally allow a line break just before the comma in a parameter list, but if the preceding line is an #endif, we have to include the break or we'll generate invalid code.
1 parent 58c2ef5 commit 53238b5

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,6 +3911,7 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
39113911
before(clause.poundKeyword, tokens: .break(.contextual, size: 0))
39123912
}
39133913
before(postfixIfExpr.config.poundEndif, tokens: .break(.contextual, size: 0))
3914+
after(postfixIfExpr.config.poundEndif, tokens: .break(.same, size: 0))
39143915

39153916
return insertContextualBreaks(base, isTopLevel: false)
39163917
} else if let callingExpr = expr.asProtocol(CallingExprSyntaxProtocol.self) {

Tests/SwiftFormatTests/PrettyPrint/IfConfigTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,4 +516,19 @@ final class IfConfigTests: PrettyPrintTestCase {
516516

517517
assertPrettyPrintEqual(input: input, expected: expected, linelength: 45)
518518
}
519+
520+
func testPostfixPoundIfInParameterList() {
521+
let input =
522+
"""
523+
print(
524+
32
525+
#if true
526+
.foo
527+
#endif
528+
, 22
529+
)
530+
531+
"""
532+
assertPrettyPrintEqual(input: input, expected: input, linelength: 45)
533+
}
519534
}

0 commit comments

Comments
 (0)