Skip to content

Commit

Permalink
Merge pull request #5295 from mathias-lang-sociomantic/fix-15396
Browse files Browse the repository at this point in the history
Fix issue 15396 - static immutable doesn't work in case statement
  • Loading branch information
9rnsr committed Dec 3, 2015
2 parents dc364a6 + 260a01f commit fb91273
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/statement.d
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
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;
}

0 comments on commit fb91273

Please sign in to comment.