`alias x = v.x;` not working in struct bodies?
Basile B.
b2.temp at gmx.com
Sat Jan 20 20:48:46 UTC 2024
On Saturday, 20 January 2024 at 09:00:22 UTC, Danilo wrote:
> I thought this should easily work, but I was wrong:
>
> [...]
Those actually would not be aliases but more _"parameter-less
expression macros"_.
In order to make those aliases working, it would be necessary to
monomorphize and recontextualize the source expression for each
use:
```d
struct Vec3 {
Vec2 v;
alias x = v.x; // cannot contextualize, no "this"
}
Vec3 v1, v2;
v1.x = 0; // -> create v1.v.x, contextualize
v2.x = 0; // cannot reuse, "this" has changed
// you have to copy and recontextualize
```
So you think that it's nice but it's actually more like a mixin.
An old PR would have allowed that but quickly a reviewer
[noticed](https://github.com/dlang/dmd/pull/11273#issuecomment-660675187) that these are not classic aliases, but something more complex, bringing possible issues.
On top of that, as there's no "scope", contextualization can lead
to ambiguous situations, reproducing the problem of what is
called "unhygienic macros"... although for dot chains, that
should not happen too much 🤞😐🤞.
More information about the Digitalmars-d
mailing list