Should aliasing a lambda expression be allowed?

Michael V. Franklin slavo5150 at yahoo.com
Wed Nov 15 01:56:58 UTC 2017


On Tuesday, 14 November 2017 at 23:41:39 UTC, Steven 
Schveighoffer wrote:
>>> An very similar problem exists for int and char overloads:
>>>
>>> alias foo = (char c) => 1;
>>> alias foo = (int i) => 4;
>>>
>>> enum int e = 7;
>>> static assert(foo(e) == 4); // fails
>> 
>> Wait a minute!  This doesn't appear to be a casting or 
>> overload problem.  Can you really overload aliases in D?
>
> In fact, I'm surprised you can alias to an expression like 
> that. Usually you need a symbol. It's probably due to how this 
> is lowered.

Boy did I "step in it" with my original post:  Started out with 
one issue and ended up with 3.

I looked at what the compiler is doing, and it is generated a new 
symbol (e.g. `__lambda4`).  I suspect this is not intended.

My question now is, should the compiler actually be treating the 
lambda as an expression instead of a new symbol, thus disallowing 
it altogether? (sigh! more breakage)?

Mike


More information about the Digitalmars-d mailing list