diff --git a/src/statement.c b/src/statement.c index 9c0a50481031..d0793021c835 100644 --- a/src/statement.c +++ b/src/statement.c @@ -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++) { diff --git a/test/fail_compilation/fail9368.d b/test/fail_compilation/fail9368.d new file mode 100644 index 000000000000..388e991a4ecd --- /dev/null +++ b/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: + } +}