Implicit enum conversions are a stupid PITA

Ellery Newcomer ellery-newcomer at utulsa.edu
Thu Mar 25 09:13:49 PDT 2010


On 03/24/2010 11:40 PM, Walter Bright wrote:
> Nick Sabalausky wrote:
>>> In D1, is there any reason I should be getting an error on this?:
>>>
>>> // module A:
>>> enum FooA { fooA };
>>> void bar(FooA x) {}
>>>
>>> // module B:
>>> import A;
>>> enum FooB { fooB };
>>> void bar(FooB x) {}
>>>
>>> bar(FooB.fooB); // Error: A.bar conflicts with B.bar (WTF?)
>
> ------- a.d -------------------
> enum FooA { fooA };
> void bar(FooA x) {}
> ------- test.d ----------------
> import a;
> enum FooB { fooB };
> void bar(FooB x) {}
>
> void test()
> {
> bar(FooB.fooB);
> }
> ------------------------------
>
> with:
>
> dmd test
>
> I do not get an error with either D1 or D2. So, if you are getting an
> error, how is your code different?

------- a.d -------------------
enum FooA { fooA };
void bar(FooA x) {}
------- test.d ----------------
import a;
mixin(`
enum FooB { fooB };
void bar(FooB x) {}
`);

void test()
{
     bar(FooA.fooA); //error
     bar(FooB.fooB);
}
------------------------------


------- a.d -------------------
enum FooA { fooA };
void bar(FooA x) {}
------- test.d ----------------
import a;
alias a.bar bar;
mixin(`
enum FooB { fooB };
void bar(FooB x) {}
`);

void test()
{
     bar(FooA.fooA);
     bar(FooB.fooB); //error
}
------------------------------

Somewhat OT: I wish enums had something analogous to struct's tupleof, 
or some way to enumerate the values of the enum, and maybe their names 
too. Do they?



More information about the Digitalmars-d mailing list