This needs to be fixed

Nick Treleaven nick at geany.org
Wed Aug 28 11:12:48 UTC 2024


On Wednesday, 28 August 2024 at 10:41:25 UTC, Manu wrote:
> On Wed, 28 Aug 2024 at 19:46, Nick Treleaven via Digitalmars-d 
> < digitalmars-d at puremagic.com> wrote:
>> > struct T
>> > {
>> >   S s;
>> >   int i;
>> >
>> >   alias a = i; // works
>> >   alias b = s.x; // Doesn't work? Why?
>> > }
>>
>> `a` is a symbol alias. `b` would be an expression if it did 
>> what you want. Instead it's the same as `S.x`, which needs an 
>> instance of S to use it at runtime.
>>
>
> Not necessarily; it doesn't need to carry around the 
> expression; it could evaluate the resolve the expression on the 
> spot.

It resolves to the field declaration `x`, which knows nothing 
about `s` - because `s.x` is not a declaration. It might confuse 
the concept of aliases if you allow them to refer to some 
sub-part of a declaration.

You could instead write:
```d
ref b() => s.x;
```

>> `tupleof` is a symbol sequence of implicit ref declarations.
>>
>
> What's a 'ref'?

https://dlang.org/changelog/pending.html#dmd.reflocal


More information about the Digitalmars-d mailing list