[Issue 19399] Different Conversion Rules for Same Value and Type -- Enum

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 14 11:29:11 UTC 2019


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

--- Comment #3 from David Eckardt <david.eckardt at sociomantic.com> ---
(In reply to David Eckardt from comment #2)
> int f(ubyte x) { return x.sizeof; }
> int f(ushort x)  { return x.sizeof; }
> 
> enum E: ushort {a = 10}
> 
> static assert(E.a.sizeof == E.sizeof); // succeeds
> static assert(E.a.sizeof == f(E.a));  // fails, f(ubyte) is called

Extended the example:

int f(ubyte x) { return x.sizeof; }
int f(ushort x)  { return x.sizeof; }

enum E: ushort {a = 10}

immutable y = E.a;

static assert(E.sizeof == 2); // succeeds
static assert(E.a.sizeof == E.sizeof); // succeeds
static assert(y.sizeof == E.sizeof); // succeeds
static assert(E.a.sizeof == f(E.a));  // fails, f(ubyte) is called

--


More information about the Digitalmars-d-bugs mailing list