[Issue 18578] New: First enum value assigned 0 instead of EnumBaseType.init

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 8 05:01:08 UTC 2018


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

          Issue ID: 18578
           Summary: First enum value assigned 0 instead of
                    EnumBaseType.init
           Product: D
           Version: D2
          Hardware: All
               URL: https://dlang.org/spec/enum.html
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: johnnymarler at gmail.com

The following example does not compile:

enum Foo { foo1 }
enum Bar : Foo { bar1 }

It fails with the message:

Error: cannot implicitly convert expression 0 of type int to Foo

We can fix it by changing the definition of Bar to this:

enum Bar : Foo { bar1 = Foo.init }

However, the spec (https://dlang.org/spec/enum.html) indicates that the value
of `bar` should already have been `Foo.init`. 

> 6. The value of an EnumMember is given by its AssignExpression. If there is no AssignExpression and it is the first EnumMember, its value is EnumBaseType.init.

It looks like the implementation is assigning the value `0` to the first enum
value instead of EnumBaseType.init.  Either the spec is wrong or this is a bug.

--


More information about the Digitalmars-d-bugs mailing list