`alias x = v.x;` not working in struct bodies?

Basile B. b2.temp at gmx.com
Sun Jan 21 15:03:15 UTC 2024


On Sunday, 21 January 2024 at 13:18:07 UTC, FeepingCreature wrote:
> I have a hard time understanding what problem you're 
> describing, but it's probably fine? Expression aliases are 
> evaluated in the context of the declaration site, not the call 
> site. This doesn't involve the grammar at all.

I'm talking about that:

```d
struct B
{
     int i;
}

struct A
{
     B b;
     alias cmp = (b.i == 0);
}

void main()
{
     A a;
     if (a.cmp) {} // a.(b.i == 0)
                   // but user wants (a.b.i) == 0
}
```

You cant just rewrite them as DotExp otherwise operands are not 
evaluated properly, or like in the example, invalid expressions 
are generated.


More information about the Digitalmars-d mailing list