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

Walter Bright newshound2 at digitalmars.com
Fri Jul 23 01:09:31 UTC 2021


On 7/22/2021 11:16 AM, Steven Schveighoffer wrote:
> But what is "all" resolutions? A combinatorial explosion of 1 or 2 possibilities 
> isn't bad. Remember, the symbol lookup *requires* a contextual type. For example:

So it appears that Swift simply gives an error if there's more than one result 
for .identifier, rather than trying to find a match that fits into the context.


> ```swift
> var x = .identifier // Compiler error, no type, even if only one type in scope 
> has a member `identifier`
> var y : SomeEnum = .identifier  // OK
> var z : SomeEnum
> z = .identifer // OK, we infer the meaning from the type of z
> ```

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's not
> that I'm trying to convince you that it should, I'm just showing what has been 
> requested and how it differs from the "mixin solution".

Thanks!


More information about the Digitalmars-d mailing list