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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jun 26 09:07:59 UTC 2020


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

--- Comment #12 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
(In reply to Walter Bright from comment #10)
> (In reply to Simen Kjaeraas from comment #5)
> > However, when the type is explicitly specified, the error occurs:
> > 
> > enum P : ulong {
> >     P = 10
> > }
> > // Should call the ulong overload, but type information is discarded and the
> > ubyte overload is called instead. This assert will fail.
> > static assert(fun(P.P) == 1);
> 
> ulong is NOT the type. The type is an enum that is implicitly convertible to
> its base type, which is ulong.
> 
> The match to both functions is by conversion, which is resolved by partial
> ordering, again picking fun(ubyte).

Agreed on all points. The problem may instead be said to be with intuition - it
seems natural that two conversions are involved when converting P.P to an int:
first the enum is converted to its base type, then that is converted to int.
Furthermore, two conversions seems like a worse match than a single conversion.
I acknowledge that's not how it works or is specified to work, but I can see
expectations being different.

--


More information about the Digitalmars-d-bugs mailing list