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

Quirin Schroll qs.il.paperinik at gmail.com
Wed Nov 23 09:53:30 UTC 2022


On Wednesday, 23 November 2022 at 09:38:06 UTC, Quirin Schroll 
wrote:
> If `ident` cannot be resolved otherwise, in the context of 
> `lazy with(arg)` an attempt for `arg.ident` is made.

A reasonable and intentional, yet noteworthy consequence is that 
nested `lazy with` resolving is reversed compared to regular 
`with`:

```d
enum A { x, y }
enum B { x, y }

void main()
{
     with (A)
     with (B)
     {
         pragma(msg, typeof(x)); // B
     }

     lazy with (A)
     lazy with (B)
     {
         pragma(msg, typeof(x)); // A
     }
}
```

Essentially, when resolving `x`, in the first case, `with(B)` 
goes ahead and resolves it (greedily). `with(A)` has nothing to 
do.
In the second case, `lazy with(B)` asks its surrounding context 
if it can resolve `x` and `lazy with(A)` then does the same. The 
answer for `lazy with(A)` is that no `x` is in scope, thus it 
attempts to resolve `x` as `A.x` and succeeds. Finally, `lazy 
with(B)` has no identifiers to resolve.


More information about the Digitalmars-d mailing list