Implicit enum conversions are a stupid PITA

Walter Bright newshound1 at digitalmars.com
Fri Mar 26 18:29:24 PDT 2010


Nick Sabalausky wrote:
> Anyway, this is what I'm doing, and it's giving me a conflict error on the 
> call to 'bar' in 'main' with DMD 1.056 (fortunately, however, it seems to 
> work fine in 2.042, so I guess the situation's improved in D2):

The mixins obscure what is going on. The same error is reproduced with the simpler:

--- a.d ---
enum FooA { foo }
void bar(FooA e) { }

--- b.d ---
enum FooB { foo }
void bar(FooB e) { }

--- test.d ---
import a;
import b;

void main()
{
     bar(FooB.foo); // Error! 'bar' conflict
}
--------------

D1 uses the earlier anti-hijacking system which disallows overloading of 
functions from different imports, unless they are specifically combined using an 
alias declaration.

D2 improves this using Andrei's suggestion that such overloading be allowed if 
and only if functions from exactly one of those imports are potential matches. 
This is why the example code works on D2.

If we change the declaration of bar in a.d to:

--- a.d ---
void bar(int e) { }
-----------

then the compilation under D2 fails, because both a.bar and b.bar are now 
candidates, due to implicit conversion rules.



More information about the Digitalmars-d mailing list