Skip to content

Commit 366da31

Browse files
authored
Merge pull request #728 from shawnhyam/fix-crash-on-enum-decl
Remove check for prioritizeKeepingFunctionOutputTogether on enum decl.
2 parents 9623f3e + 2dd68a0 commit 366da31

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,14 +1350,6 @@ fileprivate final class TokenStreamCreator: SyntaxVisitor {
13501350
}
13511351

13521352
override func visit(_ node: EnumCaseParameterClauseSyntax) -> SyntaxVisitorContinueKind {
1353-
// Prioritize keeping ") throws -> <return_type>" together. We can only do this if the function
1354-
// has arguments.
1355-
if !node.parameters.isEmpty && config.prioritizeKeepingFunctionOutputTogether {
1356-
// Due to visitation order, this .open corresponds to a .close added in FunctionDeclSyntax
1357-
// or SubscriptDeclSyntax.
1358-
before(node.rightParen, tokens: .open)
1359-
}
1360-
13611353
return .visitChildren
13621354
}
13631355

Tests/SwiftFormatTests/PrettyPrint/EnumDeclTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,4 +559,16 @@ final class EnumDeclTests: PrettyPrintTestCase {
559559
let input = "enum Foo { var bar: Int }"
560560
assertPrettyPrintEqual(input: input, expected: input + "\n", linelength: 50)
561561
}
562+
563+
func testEnumWithPrioritizeKeepingFunctionOutputTogetherFlag() {
564+
let input = """
565+
enum Error {
566+
case alreadyOpen(Int)
567+
}
568+
569+
"""
570+
var config = Configuration.forTesting
571+
config.prioritizeKeepingFunctionOutputTogether = true
572+
assertPrettyPrintEqual(input: input, expected: input, linelength: 50, configuration: config)
573+
}
562574
}

0 commit comments

Comments
 (0)