Showing with 25 additions and 3 deletions.
  1. +1 −1 src/statement.d
  2. +24 −2 test/runnable/testswitch.d
2 changes: 1 addition & 1 deletion src/statement.d
Original file line number Diff line number Diff line change
Expand Up @@ -3801,7 +3801,7 @@ public:
if (sw)
{
exp = exp.implicitCastTo(sc, sw.condition.type);
exp = exp.optimize(WANTvalue);
exp = exp.optimize(WANTvalue | WANTexpand);
/* This is where variables are allowed as case expressions.
*/
if (exp.op == TOKvar)
Expand Down
26 changes: 24 additions & 2 deletions test/runnable/testswitch.d
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,29 @@ void foo14587(Card card) {
void test14587() {
auto card = Card(11, 1);
foo14587(card);
}
}

/*****************************************/
// Issue 15396 - static immutable not recognized as constant within switch statement

void test15396()
{
static immutable Foo = "Foobar";
static const Bar = "BarFoo";

foreach (var; [ "Foobar", "BarFoo" ])
{
switch (var)
{
case Foo:
break;
case Bar:
break;
default:
assert(0, "test15396 failed");
}
}
}

/*****************************************/

Expand Down Expand Up @@ -709,8 +731,8 @@ int main()
test23();
test14352();
test14587();
test15396();

printf("Success\n");
return 0;
}