Wed, 28 Aug 2024 at 21:16, Nick Treleaven via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
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@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.

Right... that's that bug. And needs to be fixed.


It might confuse
the concept of aliases if you allow them to refer to some
sub-part of a declaration.

Definitely no; it will distinctly UN-confuse the concept of aliases.
It's been requested endlessly since forever, it's obviously how people expect it to work.
Everyone I've introduced D to has found themself here in the first few days, and it just messes everything up.
The wonky edge cases and work-arounds are a clear sign it's all gone off the rails.


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

Not the same thing at all... it's also an admission of defeat, and makes D look broken.
The path of exploration that leads to this hack is a really bad experience, and it does not do us any favours in terms of optics, or language satisfaction.


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

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

Yeah, I can't wait for the next release to land; we've been waiting literally forever for this!
That said, it doesn't really answer my question; what IS a ref? Nobody really knows; it's not really a thing that the language can properly express.

For instance, the evidence here: __traits(getParamterStorafeClasses, function, paramterByIntegerIndex)
How would you expect to detect if something is ref, or scope, or whatever? Of course, what you expect is a STRING LITERAL, which you can compare to a string of the name of the storage class.
There's no stronger evidence that storage classes are themselves such a broken idea that exist way outside of the language than passing around string literals to tell you a fact about some declaration.
C++ puts these things in the type, and while that creates some awkward cases, it's infinitely better than what we have in D in terms of expressiveness and flexibility in terms of meta programming. Ref as part of a type means it can participate in type-like expressions, inferences, etc.

What's kinda funny, is that your link to the cool ref-local feature (finally!) above will be shortly followed with "how do I detect if a local is a reference?" ... there's no __traits(getLocalVariableStorageClass, ...)

So I still don't really know; what IS a ref? It's astonishing that s.tupleof is a sequence of ref's as you say... does anything else in the language have a semantic like that? How could I synthesise something like that from anything else if I wanted to?