Skip to content

Commit 4838063

Browse files
authored
Fix parameter pack parsing bug in redundantSelf rule (#2004)
1 parent eb81f2f commit 4838063

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

Sources/FormattingHelpers.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -2791,7 +2791,8 @@ extension Formatter {
27912791
case .keyword("throws"),
27922792
.keyword("rethrows"),
27932793
.keyword("where"),
2794-
.keyword("is"):
2794+
.keyword("is"),
2795+
.keyword("repeat"):
27952796
return false // Keep looking
27962797
case .keyword where !$0.isAttribute:
27972798
return true // Not valid between end of arguments and start of body

Tests/Rules/RedundantSelfTests.swift

+62
Original file line numberDiff line numberDiff line change
@@ -3405,4 +3405,66 @@ class RedundantSelfTests: XCTestCase {
34053405
"""
34063406
XCTAssertNoThrow(try format(input, rules: [.redundantSelf]))
34073407
}
3408+
3409+
func testUnderstandsParameterPacks_issue_1992() {
3410+
let input = """
3411+
@resultBuilder
3412+
public enum DirectoryContentBuilder {
3413+
public static func buildPartialBlock<each Accumulated>(
3414+
accumulated: repeat each Accumulated,
3415+
next: some DirectoryContent
3416+
) -> some DirectoryContent where repeat each Accumulated: DirectoryContent {
3417+
Accumulate(
3418+
accumulated: repeat each accumulated,
3419+
next: next
3420+
)
3421+
}
3422+
3423+
public static func buildEither<First, Second>(
3424+
first component: First
3425+
) -> _Either<First, Second> where First: DirectoryContent, Second: DirectoryContent {
3426+
.first(component)
3427+
}
3428+
3429+
struct List<Element>: DirectoryContent where Element: DirectoryContent {
3430+
init(_ list: [Element]) {
3431+
self._list = list
3432+
}
3433+
3434+
private let _list: [Element]
3435+
}
3436+
}
3437+
"""
3438+
3439+
let output = """
3440+
@resultBuilder
3441+
public enum DirectoryContentBuilder {
3442+
public static func buildPartialBlock<each Accumulated>(
3443+
accumulated: repeat each Accumulated,
3444+
next: some DirectoryContent
3445+
) -> some DirectoryContent where repeat each Accumulated: DirectoryContent {
3446+
Accumulate(
3447+
accumulated: repeat each accumulated,
3448+
next: next
3449+
)
3450+
}
3451+
3452+
public static func buildEither<First, Second>(
3453+
first component: First
3454+
) -> _Either<First, Second> where First: DirectoryContent, Second: DirectoryContent {
3455+
.first(component)
3456+
}
3457+
3458+
struct List<Element>: DirectoryContent where Element: DirectoryContent {
3459+
init(_ list: [Element]) {
3460+
_list = list
3461+
}
3462+
3463+
private let _list: [Element]
3464+
}
3465+
}
3466+
"""
3467+
3468+
testFormatting(for: input, output, rule: .redundantSelf)
3469+
}
34083470
}

0 commit comments

Comments
 (0)