Unreachable

It definitely isn’t wrong at all, as long as it marks an impossible code path.

In this example the Token union has a lot of cases in it, but because I’m using mustAny, which returns an error if the given token is anything other than .true or .false, then I know that the subsequent switch will only have to handle those two cases and any other is impossible.

Using unreachable as a placeholder is something that I’ve done myself in the past but it’s a bit of a dangerous thing to do, because leaving a wrong unreachable in the code is much worse than leaving a wrong @panic as you might not get any immediately visible misbehavior when you hit it in release mode.

4 Likes