[Issue 5989] New: Disallow unreachable statements in switch clause

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 12 15:27:15 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5989

           Summary: Disallow unreachable statements in switch clause
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: andrej.mitrovich at gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2011-05-12 15:23:13 PDT ---
enum State
{
    init,
    done
}

void main()
{
    State state;
    int x;

    final switch (state)
    {
        x = 5;  // <- can never reach this statement
        case State.init:
        case State.done:
    }

    assert(x == 5);  // throws
}

I've run into this while adding some logging to my code. By accident I've added
a print statement right above the case statements inside a final switch, and
was puzzled why my code didn't want to log out any information.

The above code is clearly an error and I think the compiler should disallow or
at least warn about the unreachable statement.

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


More information about the Digitalmars-d-bugs mailing list