nicklockwood / SwiftFormat

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

error: 'switch' may only be used as expression in return, throw, or as the source of an assignment #1548

Closed everlof closed 10 months ago

everlof commented 10 months ago
$ swiftformat --version
0.52.6

This code:

private func constraint() -> [Int] {
    [
        1,
        2,
        {
            switch Bool.random() {
            case true: 3
            case false: 4
            }
        }(),
    ]
}

generates this code:

private func constraint() -> [Int] {
    [
        1,
        2,
        switch Bool.random() {
        case true: 3
        case false: 4
        },
    ]
}

which doesn't compile due to:

file.swift:5:9: error: 'switch' may only be used as expression in return, throw, or as the source of an assignment
        switch Bool.random() {
        ^
nicklockwood commented 10 months ago

@calda would you mind taking a look at this one?

nicklockwood commented 10 months ago

@everlof fixed in 0.52.8

everlof commented 10 months ago

Awesome! Thanks!