Enum literals, good? bad? what do you think?

Dukc ajieskola at gmail.com
Fri Jul 23 11:35:22 UTC 2021


On Friday, 23 July 2021 at 01:09:31 UTC, Walter Bright wrote:
> Are you sure that's how Swift works? Inferring the type of the 
> rvalue from the lvalue? Problems come from that, as in:
>
>    z = x + y + .identifier;
>
> For the rvalue, this becomes "top down" type inference, as 
> opposed to the usual "bottom up" type inference. D is 
> exclusively "bottom up", as it is much simpler.

It could work with bottom-up inference only. It would work the 
same way as `null` did before adding the bottom type: 
`.identifier` would be a literal of an internal compiler type, 
let's call it `EnumLiteral!"identifier"`. Values of that internal 
compiler type would implicitly convert to any enumerated type 
that defines `identifier`.



More information about the Digitalmars-d mailing list