Case Variables (Re: Two Scala annotations)

Daniel Murphy yebblies at nospamgmail.com
Sat Jun 30 06:22:55 PDT 2012


"bearophile" <bearophileHUGS at lycos.com> wrote in message 
news:dkpmzrcoppslcjqvdnze at forum.dlang.org...
>
> Currently this D2 code compiles:
>
> void main() {
>     int x = 2;
>     int y = 2;
>     switch(x) {
>         case 1: break;
>         case y: break;
>         default:
>     }
> }
>
> I think that accepting that "case y" is a compiler bug, because y is a 
> run-time value, that kills some switch optimization possibilities.
>
> Inside D code the presence or absence of an annotation semantically 
> related to that Scala @switch is able to disallow / allow the presence of 
> a run-time value among the cases.
>

I ran into this last week while working on bug 6169 - this is the only case 
(I could see) where the compiler cannot tell whether a value must be 
evaulated at compile time or not by simply looking at the context.  The idea 
being you can ignore normal safety and purity checks if you know the 
expression will be evaluated at compile time.

They seems like a corner case that somehow slipped through.  Could we just 
get rid of them? 




More information about the Digitalmars-d mailing list