Switch-case made less buggy, now with PATCH!
Chad J
chadjoan at __spam.is.bad__gmail.com
Fri Nov 20 22:49:20 PST 2009
Tim Matthews wrote:
> Chad J wrote:
>> http://d.puremagic.com/issues/show_bug.cgi?id=3536
>>
>> So Walter, with this you can keep your beloved fall-through.
>> Now can the rest of us be spared the nasty fall-through bugs, please
>> please please??
>>
>> Also, about assert(0)... I'd be happy to change what I did if Walter and
>> associates feel that adding assert(0) to the list is worth its minor
>> complications.
>>
>> (Sorry I don't have a patch for properties, but that one's harder.)
>>
>> - Chad
>
> I like having both fall through and breaking out explicit but was the
> final syntax ever discussed here first?
>
I had forgotten to add that to my test case until after I submitted the
enhancement request. I've tested it now, and it seems to work fine.
This works under the patch:
enum Foo
{
a,
b,
}
void main()
{
Foo blah = Foo.a;
final switch(blah)
{
case Foo.a!:
case Foo.b: break;
}
}
> Other possible options include 'fallthrough;' or just have the usual
> goto case for falling through too and let the compiler's optimization
> routines remove the unnecessary jumps when it sees the goto case as the
> next in sequence.
I figured this obscure token !: that no one is ever going to use for
anything else will be much easier to swallow than a new keyword or a new
kind of switch.
I'd actually be fine with just killing fallthrough altogether, but
Walter wants it (and maybe a few others too). As I ported phobos code I
also realized it was much easier to just add the !: syntax to the
compiler than it would have been to try and put gotos everywhere.
More information about the Digitalmars-d
mailing list