DIPX: Enum Literals / Implicit Selector Expression

Dennis dkorpel at gmail.com
Thu Dec 2 20:23:42 UTC 2021

I love enums and think they could use some more love in D, but 
I'm skeptical whether this particular thing can be made to work 
in D without introducing edge cases and complexity.

On Thursday, 2 December 2021 at 19:44:07 UTC, russhy wrote:
> That's a feature i long desired, and i'm pretty envious of the 
> languages that have it implemented, to name a few: Zig/Odin/Jai

Don't know about Odin/Jai, but Zig does not have function 
overloading / UFCS / template functions, so it doesn't have to 
deal with D's existing complex baggage. The DIP should figure out 
what happens in these situations:

// ambiguous overload
enum A {a}
string a() {return "a";}
auto f0(A x) {return x;}
auto f0(string x) {return x;}
pragma(msg, typeof(f0(.a))); // string?

// difficult type inference
enum A {a, b}
enum B {a, b, c}
auto f1(T)(T x) {return x;}
pragma(msg, typeof(f1(.a))); // ?
pragma(msg, typeof([.a, .b, .c])); // B[]?

// Subtype member shadowing
enum A {
     a = 1,
     c = 3,

enum B : A {
     a = A.c,
     b = A.a,

immutable A[] arr = [.a, .b];
pragma(msg, arr); // ?
There's probably more.

More information about the Digitalmars-d mailing list