On 18 February 2014 08:31, Walter Bright <newshound2@digitalmars.com> wrote:
On 2/17/2014 5:48 AM, Ary Borenszweig wrote:
On 2/16/14, 5:03 PM, Walter Bright wrote:
It originally was not required, but there was a campaign by a lot of D
users to make it required to deal with the common bug of adding a value
in one switch statement but forgetting to add it to another
corresponding one.

Could you show an example of such scenario? I don't get it.

Having a set of bit flags, and adding another bit flag later, and failing to account for that in existing switch statements.

It sounds like that's basically the same as final switch, just without the enum key to communicate the strong concept.

If I were to imagine a solution to that problem I would have also applied final switch, but in the case it's dealing with integers and not enums and therefore can't know which values are valid and tell you that you missed one, it should insert an implicit 'default: assert(0);' (since final switch isn't meant to have 'default' cases), this way any case you don't explicitly handle is considered invalid, and you'll catch your mistake immediately. I expect final switch on enum's must do this anyway (at least in debug)? It's possible to receive a value that's not a recognised enum key; what happens in that case?
It seems effectively the same to me.