SE-0380: `if` and `switch` expressions

Such returns would be confusable with returns from the function itself.

Somewhat related: To avoid confusion about where return returns from I'd use two different types of brackets: one for functions / blocks and another for statements:

func foo() [
    if condition {
        return // from function
    }
    for item in items {
        ...
        return // from function
    }
    foo.bar.baz [ // aha, square brackets! so this is a closure (block), not a statement.
        ...
        return // from closure
        if condition { return } // from closure
    ]
    DipatchQueue.main.async [ // ditto
        return // from closure
    ]
]

It doesn't look too odd or radical, although I didn't find precedents in other languages (other than the opposite: using { } for array constants in C). This would make different things slightly more (visually) different and could help during debugging (how many times I was stepping though a line ".... {" expecting to be on the next line but ending up elsewhere because that was a closure.)

1 Like