Skip to content

Commit

Permalink
Merge pull request #1534 from AndrejMitrovic/Fix9368
Browse files Browse the repository at this point in the history
Issue 9368 - Final switch on typedef'ed enum is not properly checked
  • Loading branch information
9rnsr committed Jan 28, 2013
2 parents 2a6fefe + 1be6b75 commit 1658755
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/statement.c
Expand Up @@ -3236,14 +3236,18 @@ Statement *SwitchStatement::semantic(Scope *sc)
#if DMDV2
if (isFinal)
{ Type *t = condition->type;
while (t->ty == Ttypedef)
while (t && t->ty == Ttypedef)
{ // Don't use toBasetype() because that will skip past enums
t = ((TypeTypedef *)t)->sym->basetype;
}
if (te)
Dsymbol *ds;
EnumDeclaration *ed = NULL;
if (t && ((ds = t->toDsymbol(sc)) != NULL))
ed = ds->isEnumDeclaration(); // typedef'ed enum
if (!ed && te && ((ds = te->toDsymbol(sc)) != NULL))
ed = ds->isEnumDeclaration();
if (ed)
{
EnumDeclaration *ed = te->toDsymbol(sc)->isEnumDeclaration();
assert(ed);
size_t dim = ed->members->dim;
for (size_t i = 0; i < dim; i++)
{
Expand Down
24 changes: 24 additions & 0 deletions test/fail_compilation/fail9368.d
@@ -0,0 +1,24 @@
// PERMUTE_ARGS:
// REQUIRED_ARGS: -d
/*
TEST_OUTPUT:
---
fail_compilation/fail9368.d(20): Error: enum member b not represented in final switch
---
*/

enum E
{
a,
b
}

void main()
{
typedef E F;
F f;
final switch (f)
{
case F.a:
}
}

0 comments on commit 1658755

Please sign in to comment.