nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.9k stars 639 forks source link

unusedArguments fails when an argument is reassigned to a for loop's parameter #1184

Closed nicorichard closed 2 years ago

nicorichard commented 2 years ago

A minimally reproducible example for 0.49.8

func foo(index: Int) {
    for index in 0..<1 {}
    print(index)
}

will be formatted to

func foo(index _: Int) {
    for index in 0..<1 {}
    print(index) // compile error
}

This seems to be a regression which may have been caused by the solution for my previous issue #1174

The issue does not occur for version 0.49.6


Another example of a failing case in the same category:

func foo(index: Int) {
    for (index, value) in [].enumerated() {}
    print(index)
}
nicklockwood commented 2 years ago

Seems like a duplicate of https://github.com/nicklockwood/SwiftFormat/issues/1183 - I've landed a fix in develop already.

nicklockwood commented 2 years ago

@nicorichard fixed in 0.49.9