[Issue 5713] Broken final switch on ints

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 20 14:06:04 PDT 2011


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



--- Comment #4 from bearophile_hugs at eml.cc 2011-08-20 14:05:58 PDT ---
This code is a reduction of real code, with small changes. It shows why this
final switch brokeness makes final switch not as safe as advertised:


void main() {
    enum Foo { A, B }
    enum Bar { C = 5, D = 6 }
    int fe; // first mistake, fe is not Foo
    bool someCondition = true;
    if (someCondition)
        fe = Bar.C; // second mistake, fe is not assigned to a Foo
    final switch (fe) {
        case Foo.A: break;
        case Foo.B: break;
    }
}


The code contains two mistakes, the first is giving fe int type instead of Foo.
The second mistake is assigning  to fe an invalid enum value. The final switch
doesn't catch the wrong enum value of fe, and it asks for no default case
because it's supposed to be complete. The final switch spec need to be
improved.

-- 
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