Thread overview
[Issue 24656] enums with explicit EnumBaseType incorrectly matching multiple overloads.
Jul 09
basile-z
Jul 09
basile-z
Jul 09
basile-z
July 09
https://issues.dlang.org/show_bug.cgi?id=24656

--- Comment #1 from dave287091@gmail.com ---
Furthermore, the following additional function values to compile, which is very counter-intuitive as E shouldn’t implicitly convert to byte as its EnumBaseType is ubyte and it has a value outside the range of byte.

```
void indirect(E e){
    foo(e);
}
```

--
July 09
https://issues.dlang.org/show_bug.cgi?id=24656

--- Comment #2 from dave287091@gmail.com ---
(In reply to dave287091 from comment #1)
> Furthermore, the following additional function values to compile, which is

“values to compile” -> “fails to compile"

--
July 09
https://issues.dlang.org/show_bug.cgi?id=24656

--- Comment #3 from basile-z <b2.temp@gmx.com> ---
This looks invalid to me. Implcit conversions between signed and unsigned allows things like

```
void main(){
    byte a;
    a = ubyte(255);
}
```

Problem in the original report is more about signess but signess does not play a role in overload resolution.

--
July 09
https://issues.dlang.org/show_bug.cgi?id=24656

basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b2.temp@gmx.com

--- Comment #4 from basile-z <b2.temp@gmx.com> ---
Also "to which point enum members are strongly-typed ?" is the underlying question. You expect some kind of VRP (or maybe constant folding) but that is not the case.

--
July 09
https://issues.dlang.org/show_bug.cgi?id=24656

--- Comment #5 from dave287091@gmail.com ---
(In reply to basile-z from comment #4)
> Also "to which point enum members are strongly-typed ?" is the underlying question. You expect some kind of VRP (or maybe constant folding) but that is not the case.

I expect that specifying a base type means that enum is converted to that type before any other implicit conversion.

--
July 09
https://issues.dlang.org/show_bug.cgi?id=24656

--- Comment #6 from basile-z <b2.temp@gmx.com> ---
(In reply to dave287091 from comment #5)
> (In reply to basile-z from comment #4)
> > Also "to which point enum members are strongly-typed ?" is the underlying question. You expect some kind of VRP (or maybe constant folding) but that is not the case.
> 
> I expect that specifying a base type means that enum is converted to that type before any other implicit conversion.

That goes a bit against how subtyping works:

```
class A {}
class B : A {}

void test(A a){ assert(0, "no the top-most type is tried first"); }
void test(B b){}

void main(){(new B).test();} ```

That being said, I'll stop to argument there. I'm not a big fan of the overloading principle. The issue you've opened is exactly what it leads to, i.e confusion.

Side note: sure in D it's a bit more complex, as overloading participate to pick the right template, based on how constraints are evaluated ;)

--