Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
everlof opened this issue Oct 10, 2023 · 3 comments
Labels
bug fixed in develop bug/feature resolved in the develop branch

Comments

@everlof
Copy link

everlof commented Oct 10, 2023

$ 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
Copy link
Owner

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

@nicklockwood
Copy link
Owner

@everlof fixed in 0.52.8

@everlof
Copy link
Author

everlof commented Oct 18, 2023

Awesome! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fixed in develop bug/feature resolved in the develop branch
Projects
None yet
Development

No branches or pull requests

2 participants