nicklockwood / SwiftFormat

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

Breaks code by introducing a space in a function attribute #1666

Closed JaapWijnen closed 2 months ago

JaapWijnen commented 3 months ago

The following code is broken when running swiftformat as it introduces a space: @derivative(of: subscript.get) -> @derivative(of: subscript .get) This specifically impacts functions that implement custom derivatives for subscript getters (or setters in the future)

import _Differentiation

struct Thing: Differentiable {
    var values: [Double]

    @differentiable(reverse)
    subscript(index: Int) -> Double {
        mutating get {
            values[index]
        }
    }

    @derivative(of: subscript.get)
    mutating func vjpSubscriptGet(index: Int) -> (value: Double, pullback: (Double.TangentVector, inout Self.TangentVector) -> Void) {
        return (
            value: values[index],
            pullback: { _, _ in
            }
        )
    }
}
JaapWijnen commented 3 months ago

Thanks!

nicklockwood commented 2 months ago

@JaapWijnen fixed in 0.53.6