SE-0380 was accepted with an amendment banning all non-error control flow in if
and switch
expressions.
The discussion about return
ambiguity was in reference to the immediately-applied closure workaround for the lack of if
/switch
expressions:
Finally, a closure can be used to simulate an if expression:
let bullet = { if isRoot && (count == 0 || !willExpand) { return "" } else if count == 0 { return "- " } else if maxDepth <= 0 { return "▹ " } else { return "▿ " } }()
This also requires returns, plus some closure ceremony. But here the returns are more than ceremony – they require extra cognitive load to understand they are returning from a closure, not the outer function.