Bug 5989 – Disallow unreachable statements in switch clause
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-05-12T15:23:00Z
Last change time
2011-05-12T15:37:34Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2011-05-12T15:23:13Z
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.
Comment #1 by bearophile_hugs — 2011-05-12T15:31:27Z
Dupe of bug 3820 ?
Comment #2 by bearophile_hugs — 2011-05-12T15:33:44Z
*** This issue has been marked as a duplicate of issue 3820 ***
Comment #3 by andrej.mitrovich — 2011-05-12T15:37:34Z