nicklockwood / SwiftFormat

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

Outputted code doesn't build #1547

Closed everlof closed 10 months ago

everlof commented 10 months ago

Swiftformat: 0.52.6

Running: swiftformat file.swift --swiftversion 5.9 on this:

private enum Format {
    case uint8
    case uint16

    var bytes: Int {
        {
            switch self {
            case .uint8: return UInt8.bitWidth
            case .uint16: return UInt16.bitWidth
            }
        }() / 8
    }
}

gives this:

private enum Format {
    case uint8
    case uint16

    var bytes: Int {
        switch self {
        case .uint8: UInt8.bitWidth
        case .uint16: UInt16.bitWidth
        } / 8
    }
}

which doesn't compile:

file.swift:9:10: error: consecutive statements on a line must be separated by ';'
        } / 8
         ^
         ;
file.swift:9:11: error: unary operator cannot be separated from its operand
        } / 8
          ^~

file.swift:7:28: warning: expression of type 'Int' is unused
        case .uint8: UInt8.bitWidth
                     ~~~~~~^~~~~~~~
file.swift:8:30: warning: expression of type 'Int' is unused
        case .uint16: UInt16.bitWidth
                      ~~~~~~~^~~~~~~~
file.swift:9:11: error: '/' is not a prefix unary operator
        } / 8
          ^     
nicklockwood commented 10 months ago

@calda another one - still present in 0.52.7.

nicklockwood commented 10 months ago

@everlof fixed in 0.52.8

everlof commented 10 months ago

Also great! :) Thanks!