www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7358] New: `final switch` over enum should add throwing default in debug mode at least

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7358

           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
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com



---
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: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 24 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7358


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |yebblies gmail.com
         AssignedTo|nobody puremagic.com        |yebblies gmail.com



https://github.com/D-Programming-Language/dmd/pull/673

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 31 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7358


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc




 https://github.com/D-Programming-Language/dmd/pull/673
I don't like it. There are better solutions, like: is(typeof(E.a | E.b) == int) This means f(E.a | E.b) becomes a compile-time error, a type mismatch. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 05 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7358




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/b9ad0b8517c23fa4deca3ddb433dfbb0fab8fb65
Issue 7358 - final switch over enum should add throwing default in debug mode
at least

Add a throwing default case when compiled with asserts on.

https://github.com/D-Programming-Language/dmd/commit/638d81d792d5f12c887de3da6ab00c07d9f227b2


Issue 7358 - final switch over enum should add throwing default in debug mode

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 30 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7358


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 30 2012