Skip to content

Commit

Permalink
Fixed bug in Void handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Nov 3, 2016
1 parent 9f3604b commit fba8f28
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion SwiftFormat/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,8 @@ public func void(_ formatter: Formatter) {
formatter.tokenAtIndex(prevIndex) == .startOfScope("("),
let nextIndex = formatter.indexOfNextToken(fromIndex: i, matching: { !$0.isWhitespaceOrLinebreak }),
formatter.tokenAtIndex(nextIndex) == .endOfScope(")") {
if formatter.nextNonWhitespaceOrCommentOrLinebreakToken(fromIndex: nextIndex) == .symbol("->") {
if let nextToken = formatter.nextNonWhitespaceOrCommentOrLinebreakToken(fromIndex: nextIndex),
[.symbol("->"), .keyword("throws"), .keyword("rethrows")].contains(nextToken) {
// Remove Void
formatter.removeTokensInRange(prevIndex + 1 ..< nextIndex)
} else if formatter.options.useVoid {
Expand Down
7 changes: 7 additions & 0 deletions SwiftFormatTests/RulesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2255,6 +2255,13 @@ class RulesTests: XCTestCase {
XCTAssertEqual(try! format(input + "\n", rules: defaultRules), output + "\n")
}

func testVoidThrowsIsNotMangled() {
let input = "(Void) throws -> Void"
let output = "() throws -> Void"
XCTAssertEqual(try! format(input, rules: [void]), output)
XCTAssertEqual(try! format(input + "\n", rules: defaultRules), output + "\n")
}

// MARK: useVoid = false

func testUseVoidOptionFalse() {
Expand Down

0 comments on commit fba8f28

Please sign in to comment.