Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1534 from AndrejMitrovic/Fix9368

Issue 9368 - Final switch on typedef'ed enum is not properly checked
  • Loading branch information...
commit 16587559891280c9a21a648bc39a3d3b4b7c49f5 2 parents 2a6fefe + 1be6b75
Hara Kenji 9rnsr authored
Showing with 32 additions and 4 deletions.
  1. +8 −4 src/statement.c
  2. +24 −0 test/fail_compilation/fail9368.d
12 src/statement.c
View
@@ -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++)
{
24 test/fail_compilation/fail9368.d
View
@@ -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:
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.