Bug 18578 – First enum value assigned 0 instead of EnumBaseType.init

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-08T05:01:08Z
Last change time
2023-09-20T14:15:42Z
Keywords
pull, rejects-valid
Assigned to
No Owner
Creator
Jonathan Marler

Comments

Comment #0 by johnnymarler — 2018-03-08T05:01:08Z
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.
Comment #1 by razvan.nitu1305 — 2018-03-26T15:45:17Z
Comment #2 by johnnymarler — 2018-03-26T15:49:13Z
Also noticed this one: https://github.com/dlang/dmd/pull/7996/files I think @LemonBoy created this PR without knowing that I had made a bug for this issue.
Comment #3 by github-bugzilla — 2018-03-26T22:54:28Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/12503d908853e65732995351ee9579cfb1384fa0 Fix Issue 18578 - First enum value assigned 0 instead of EnumBaseType.init https://github.com/dlang/dmd/commit/5cbd4730e0e0d0bdfe8bf818ad85cea64608990b Merge pull request #8090 from RazvanN7/Issue_18578 Fix Issue 18578 - First enum value assigned 0 instead of EnumBaseType.init merged-on-behalf-of: Walter Bright <[email protected]>
Comment #4 by b2.temp — 2020-08-15T17:57:16Z
new TC: --- enum E { e1 = 1 } enum F: E { f1 } static assert(F.init == 1); --- > /tmp/temp_7F28124F66B0.d(4,1): Error: static assert: `cast(F)cast(E)0 == 1` is false
Comment #5 by nick — 2023-01-30T17:02:28Z
*** Issue 23492 has been marked as a duplicate of this issue. ***
Comment #6 by dlang-bot — 2023-09-09T14:23:13Z
@ntrel created dlang/dlang.org pull request #3694 "First enum member is converted from 0 to base type" fixing this issue: - First enum member is converted from 0 to base type Fix Issue 18578 - First enum value assigned 0 instead of EnumBaseType.init. https://github.com/dlang/dlang.org/pull/3694
Comment #7 by dlang-bot — 2023-09-20T14:15:42Z
dlang/dlang.org pull request #3694 "[spec] First enum member is converted from 0 to base type" was merged into master: - e1cc573c6aabe8619aa94a52f7886d4f4072cc8a by Nick Treleaven: First enum member is converted from 0 to base type Fix Issue 18578 - First enum value assigned 0 instead of EnumBaseType.init. https://github.com/dlang/dlang.org/pull/3694