Summary: `final switch` over enum should add throwing default
                    in debug mode at least
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Denis <> 2012-01-24 14:52:00 MSK 
Inspired by bug 5713, comment 5

Even if every enum member is present a default statement should be added at
least in debug mode to catch such situation if enum members doesn't cover every
possible value:
enum E { a = 1, b }
void f(E e) {
    final switch (e) {
        case E.a:
        case E.b:
void g() {
    f(E.a | E.b); // like `f(cast(E)3);`, should throw

As was written in bug 5713 description:
>The purpose of "final switch" is to increase code safety compared to normal 
>switches on enums.
So it's really bad that it works silently incorrect. Personally I have used
`final switch` carefully and thought about it's behavior in such situation
since it has been introduced because it is undocumented. So the documentation
should be fixed too.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to