[Issue 21460] implicit conversion between two unrelated enum is accepted

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 8 20:20:12 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21460

--- Comment #1 from Basile-z <b2.temp at gmx.com> ---
This is caused by the automatic integer promotion on the condition.
It is done before evaluation of the cases so it "mind-fuck" the type checks
that are correct when no promotion is involved:

---
enum Good  { a = 1 }
enum Bad   { a = 2 }

void main()
{
    Good good;
    switch (good) // no promotion
    {
    case Bad.a : break; // error as expected
    default:
    }
} 
---

VS

---
enum Good : ubyte { a = 1 }
enum Bad  : ubyte { a = 2 }

void main()
{
    Good good;
    switch (good) // by promotion replaced by  'cast(int) good'
    {
    case Bad.a : break; // OK because convert to int
    default:
    }
} 
---

--


More information about the Digitalmars-d-bugs mailing list