nicklockwood / SwiftFormat

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

Invalid self. in closure capture list #1411

Closed keith closed 1 year ago

keith commented 1 year ago

With this code:

class Thing {
    var a: String? { nil }

    func foo() {
        let b = ""
        { [weak a = b] _ in }
    }
}

And formatting with --self insert, you get:

class Thing {
    var a: String? { nil }

    func foo() {
        let b = ""
        { [weak self.a = b] _ in }
    }
}

Which is invalid but also missing the fact that the a in the capture list is attempting to shadow the member variable.

nicklockwood commented 1 year ago

@keith fixed in 0.51.5