Feedback Thread: DIP 1044--Enum Type Inference--Community Review Round 1

Walter Bright newshound2 at digitalmars.com
Sat Nov 19 04:33:04 UTC 2022


I'm looking at the DIP:

   auto y = [A.a, $b, $c, $d]; // typeof(y) = A[]
   auto z = [A.c, 64, $b, $b]; // typeof(z) = int[]

Note that the type of an array literal is determined by the common type of all 
the elements, not just the first element:

   auto a [ 0, 1, 3.0, 4 ]; // double[4]

The DIP says: "ETI is also allowed in array literals for which an explicit enum 
type can be inferred"

I'm not sure what the rule is. Is it the first element of enum type that sets 
the rule (left to right), or does:

   auto a = [ $a, A.b, $c ];

work?

What about nested arrays:

    auto a = [[A.b, $b], [$c, $d]];

?


More information about the Digitalmars-d mailing list