Bug 20777 – User defined type as enum base type fails to compile.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-04-27T15:43:21Z
Last change time
2022-02-08T03:30:05Z
Keywords
pull
Assigned to
No Owner
Creator
crazymonkyyy

Comments

Comment #0 by crazymonkyyy — 2020-04-27T15:43:21Z
>struct fooint{ > enum isfoo=true; > enum isbar=false; > int i; > auto opBinary(string op:"+")(int j){ > return fooint(i+j); > } > alias i this; > @property fooint max(){return fooint(int.max);} >} >static assert(fooint(0)+1 != fooint(0).max); >static assert(fooint(0)+1 != fooint(0)); >enum foolist {hi=fooint(0),bye,fizz,buzz} >//no property max for type fooint, did you mean bar.fooint.max "If there is no AssignExpression and it is not the first EnumMember, it is given the value of the previous EnumMember+1. If the value of the previous EnumMember is the .max property if the previous EnumMember's type, it is an error. If the value of the previous EnumMember+1 is the same as the value of the previous EnumMember, it is an error."
Comment #1 by snarwin+bugzilla — 2021-04-06T13:27:23Z
Simplified example: --- struct fooint { int i; auto opBinary(string op : "+")(int j) { return fooint(i + j); } @property fooint max() { return fooint(int.max); } } enum foolist { hi = fooint(0), bye } --- Produces the following error message: --- Error: no property `max` for type `fooint`, did you mean `onlineapp.fooint.max`? ---
Comment #2 by dlang-bot — 2022-02-07T21:36:25Z
@maxhaton created dlang/dmd pull request #13620 "Fix Issue 20777 - Extend enum base type semantic to user defined type…" fixing this issue: - Fix Issue 20777 - Extend enum base type semantic to user defined type's with operator overloads https://github.com/dlang/dmd/pull/13620
Comment #3 by dlang-bot — 2022-02-08T03:30:05Z
dlang/dmd pull request #13620 "Fix Issue 20777 - Extend enum base type semantic to user defined type…" was merged into master: - 8e81413ebbe0587e8cdb5ebb5ee8bc93ae2693bd by Max Haughton: Fix Issue 20777 - Extend enum base type semantic to user defined type's with operator overloads https://github.com/dlang/dmd/pull/13620