Switch-case made less buggy, now with PATCH!

Chad J chadjoan at __spam.is.bad__gmail.com
Sun Nov 22 13:37:57 PST 2009


Ellery Newcomer wrote:
> On 11/20/2009 07:51 PM, 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
> 
> <patch critic>
> 
> switch(i){
>  case 1:       //this should not yield an error. change it.
>  case 2:
>    blah;
>    break;
> }
> 

Reasonable.

> switch(i){
>  case 1:
>    {
>      break;
>    }           //this should not yield an error. change it.
> }
> 

Doable.  But do we want to?  I think it requires semantic analysis.
(Yeah I used SA for mine anyways, but mine could have be done in parse
as Don mentioned.)

This is a good point to mention at any rate.  I forgot I had to deal
with these.  It's one of those things that can break code, even though
it has little to do with fallthrough.

> switch(i){
>   default:
>     blah;      //this should yield an error. change it.
>   case 0:
>     case0onlyblah;
> }
> 

It already does.

> 
> </patch critic>

Thanks
- Chad



More information about the Digitalmars-d mailing list