DIPX: Enum Literals / Implicit Selector Expression

Steven Schveighoffer schveiguy at gmail.com
Wed Jul 6 01:36:21 UTC 2022


On 7/5/22 9:12 PM, Timon Gehr wrote:
> 
> Then you get the same behavior as with lambdas.
> 
> ```d
> enum Foo{ a, b }
> enum Bar{ b, c }
> 
> void fun(Foo foo, int x){ writeln(foo); }
> void fun(Bar bar, float x){ writeln(bar); }
> 
> void main(){
>      fun(:b, 1);
> }
> ```
> 
> So I guess you are saying this should call the first overload?

Yeah, I think this is better, it's what I would expect. But I can see 
your point. It's also fine your way as well. The fact that there's very 
few types that convert to each other limits this case to very few 
overload sets.

> The reason I am bringing this up is that here, those calls are both legal:
> 
> ```d
> fun(Foo.b, 1); // calls first overload
> fun(Bar.b, 1); // calls second overload
> ```
> 
> I don't think this is a huge problem, but it might qualify as a pitfall. 
> (It could be argued that removing the enum name from working code should 
> either preserve the behavior or error out.) The overloading rules are 
> not getting any more complicated though.

Either way is arguable I think. There is something to be said for erring 
on the side of caution (or ambiguity in this case).

-Steve


More information about the Digitalmars-d mailing list