www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21460] New: implicit conversion between two unrelated enum is


          Issue ID: 21460
           Summary: implicit conversion between two unrelated enum is
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: b2.temp gmx.com

This code compiles but should not

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

void main()
    Good good;
    switch (good)
    case Bad.a : break;

The compilation halts if the base type, `ubyte`, is not specified.

I dont see a specification for that behavior. The only implicit conv rule
related to named enums is:

  "A named enum member can be implicitly cast to its EnumBaseType, but 
  EnumBaseType types cannot be implicitly cast to an enum type."

It is not clear if this covers the problem described in this report.

Dec 08 2020