DIPX: Enum Literals / Implicit Selector Expression

Steven Schveighoffer schveiguy at gmail.com
Wed Jul 6 00:57:35 UTC 2022


On 7/5/22 7:53 PM, Timon Gehr wrote:
> So I guess actually there is one open question: At what matching level 
> should a polysemous enum literal match an enum type? If it's considered 
> a perfect match, other parameters might cause a resolution of a name 
> clash, if it's considered a match with implicit conversion, this does 
> not happen.

I'm concerned about that though, because this brings what should be an 
exact match (if you specified the enum fully) into the same category as 
an implicit conversion.

For example:

```d
enum E { one }

foo(E e, uint u); // 1
foo(E e, int i); // 2

foo(E.one, 1U); // calls 1
foo(E.one, 1); // calls 2

// Now both foo's are at the same level, and there's an ambiguity error
// because uint <-> int
foo(#one, 1U);
```

I'd much rather just consider that the type is deferred until the 
expression is used, and then resolved to the correct type based on the 
way it's used. The sole focus of this feature should be to just omit 
enum names when they are *obvious*.

-Steve


More information about the Digitalmars-d mailing list