[Pitch] if and switch expressions

I don't really see why it would be, any more than a throw in an if statement today might. You need try on function calls that throw to make sure it's clear your function might exit. But open-coded throws inside a function are clear enough.

as that snuck through and is legal under the proposal but had a surprising side effect that he didn't intend

I don't think a compiler can stop you writing incorrect code. There is a big difference between things a compiler can catch – type errors, unreachable code, flagging calls that would exit the function abruptly because they throw – and then there are logic errors (like getting your if and else branches the wrong way around) that are just unavoidably on the programmer. The extra return typo falls into the latter bucket IMO.

2 Likes