Lambdas Scope
Timon Gehr
timon.gehr at gmx.ch
Mon Apr 11 10:34:12 UTC 2022
On 11.04.22 11:11, Salih Dincer wrote:
> How is this possible? Why is it compiled? Don't the same names in the
> same scope conflict?
>
> ```d
> int function(int) square;
> void main()
> {
> square = (int a) => a * a;
> int square = 5.square;
> assert(square == 25);
> }
> ```
>
> Thanks, SDB at 79
- Local variables in a function can hide variables in less nested
scopes. (Such hiding is only an error for nested block scopes within the
same function.)
- UFCS always looks up names in module scope, it does not even check locals.
More information about the Digitalmars-d-learn
mailing list