`alias x = v.x;` not working in struct bodies?
Danilo
codedan at aol.com
Sat Jan 20 09:49:06 UTC 2024
On Saturday, 20 January 2024 at 09:00:22 UTC, Danilo wrote:
> ```d
> struct Vec2 {
> int x, y;
> }
>
> struct Vec3 {
> Vec2 v;
> alias x = v.x;
> alias y = v.y;
> ...
> }
> ```
>
> Can't `alias` targets be used in method bodies?
>
> In the method/constructor parameters it's working as expected.
> But not inside the bodies?
>
> Documentation:
> - https://dlang.org/spec/declaration.html#alias
> - https://dlang.org/spec/declaration.html#alias-variable
>
> According to the link `alias-variable` I would expect my
> example to work.
> Aliasing a variable (struct member), it's a symbol.
We figured it out on Discord. `alias` works only with static
variables and members:
```d
struct Vec2 {
static int x, y;
}
struct Vec3 {
static Vec2 v;
...
```
The documentation i mentioned above didn't explicitely say it's
for use with `static` variables/members only.
More information about the Digitalmars-d
mailing list