"bearophile" <[email protected]> wrote in message news:[email protected]... > > 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?
