Skip to content

Commit

Permalink
Merge pull request #1417 from AndrejMitrovic/Fix4540
Browse files Browse the repository at this point in the history
Issue 4540 - Better diagnostic for wrong switch type.
  • Loading branch information
9rnsr committed Jan 11, 2013
2 parents c7215bc + 8ab6ab2 commit 98e20bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -3183,7 +3183,8 @@ Statement *SwitchStatement::semantic(Scope *sc)
}
else
{ condition = condition->integralPromotions(sc);
condition->checkIntegral();
if (!condition->type->isintegral())
error("'%s' must be of integral or string type, it is a %s", condition->toChars(), condition->type->toChars());
}
condition = condition->optimize(WANTvalue);

Expand Down
16 changes: 16 additions & 0 deletions test/fail_compilation/diag4540.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag4540.d(4): Error: 'x' must be of integral or string type, it is a float
---
*/

#line 1
void main()
{
float x;
switch (x)
{
default:
}
}

0 comments on commit 98e20bc

Please sign in to comment.