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

IchorDev zxinsworld at gmail.com
Sun Nov 20 15:06:24 UTC 2022


On Saturday, 19 November 2022 at 04:33:04 UTC, Walter Bright 
wrote:
> 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?

Before the structural pass the DIP explicitly stated that it was 
determined by the first element. I felt that this was enough to 
conclusively remove any ambiguity, however Micheal was of the 
opinion that this was not necessary, and removed it because:
> D already infers the type of literals when it can, so I don't 
> think there's any need to be verbose in describing it. The 
> examples speak well enough.

If what they said is not the case, do you feel that the explicit 
first-element rule should be re-added?

On Saturday, 19 November 2022 at 04:33:04 UTC, Walter Bright 
wrote:
> What about nested arrays:
>
>    `auto a = [[A.b, $b], [$c, $d]];`
>
> ?

Since `auto b = [[1,2],[0.3,0.4]];` gives a type incompatibility 
error, I think ETI should be consistent with this behaviour:
The two arrays would be evaluated separately, so the second one 
would just look like `[$c, $d]` to the parser and it would return 
an error.


More information about the Digitalmars-d mailing list