D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20777 - User defined type as enum base type fails to compile.
Summary: User defined type as enum base type fails to compile.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-04-27 15:43 UTC by crazymonkyyy
Modified: 2022-02-08 03:30 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description crazymonkyyy 2020-04-27 15:43:21 UTC
>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 Paul Backus 2021-04-06 13:27:23 UTC
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 Dlang Bot 2022-02-07 21:36:25 UTC
@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 Dlang Bot 2022-02-08 03:30:05 UTC
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