Re: case statement allows for runtime values,

2011-04-19 Thread bearophile
Andrej Mitrovic: > Got it. Bug is reported. Good. > You can compare anything in an if statement, so why is switch more limited? switch has stronger requirements than a series of if statements and its uses such extra information to create assembly code that's more efficient than a series of i

Re: case statement allows for runtime values,

2011-04-19 Thread Jesse Phillips
Andrej Mitrovic Wrote: > Got it. Bug is reported. > > Btw, is there a specific reason why non-const values are not allowed? > > I mean, doesn't a switch statement like this: > switch(value) > { > case 1: > foo(); break; > case 2: > bar(); break; > default: > d

Re: case statement allows for runtime values,

2011-04-19 Thread Andrej Mitrovic
Got it. Bug is reported. Btw, is there a specific reason why non-const values are not allowed? I mean, doesn't a switch statement like this: switch(value) { case 1: foo(); break; case 2: bar(); break; default: doo(); } expand to: if (value == 1) foo(); el

Re: case statement allows for runtime values,

2011-04-19 Thread Jesse Phillips
Andrej Mitrovic Wrote: > On 4/19/11, Jesse Phillips wrote: > > Yes bug. Not this part though > > > >> switch (x = foo(y)) > > > > Yeah that I know. > > Do you happen to know if this bug is already filed or should I file it? I would not know. As long as you do a best guess search on what yo

Re: case statement allows for runtime values, a case of accepts-invalid?

2011-04-19 Thread Andrej Mitrovic
*I've searched bugzilla and couldn't find an entry for this particular case.

Re: case statement allows for runtime values, a case of accepts-invalid?

2011-04-19 Thread Andrej Mitrovic
On 4/19/11, Jesse Phillips wrote: > Yes bug. Not this part though > >> switch (x = foo(y)) > Yeah that I know. Do you happen to know if this bug is already filed or should I file it?

Re: case statement allows for runtime values, a case of accepts-invalid?

2011-04-19 Thread Jesse Phillips
Andrej Mitrovic Wrote: > int foo(ref int y) > { > y = 5; > return y; > } > > void main() > { > int x = 1; > int y = 2; > > switch (x = foo(y)) > { > case y: > writeln("x == y"); > default: > } > > assert(x == 5); > assert(y

case statement allows for runtime values, a case of accepts-invalid?

2011-04-19 Thread Andrej Mitrovic
int foo(ref int y) { y = 5; return y; } void main() { int x = 1; int y = 2; switch (x = foo(y)) { case y: writeln("x == y"); default: } assert(x == 5); assert(y == 5); } According to the docs: The case expressions must all