Wrong enum comparisons

bearophile bearophileHUGS at lycos.com
Sun May 27 12:45:22 PDT 2012


In some code I have created a small bug that can be reduced to 
something like this, that the D compiler has not caught at 
compile-time:


enum E1 { A, B }
enum E2 { C, D }
void main() {
     E1[2] a;
     with (E2)
         assert(a[0] == D);
}


Why isn't D able to statically tell when you compare values of 
different enums?
How much work is implementing this compile-time test inside the D 
front-end?

Thank you,
bye,
bearophile


More information about the Digitalmars-d mailing list