This needs to be fixed

Timon Gehr timon.gehr at gmx.ch
Mon Aug 26 08:40:02 UTC 2024


On 8/26/24 07:21, Walter Bright wrote:
> On 8/24/2024 9:36 AM, Manu wrote:
>> alias x = s.tupleof; // this works
>> alias y = s.tupleof[0]; // this is a compile error?!
> 
> 
> Can you please repost with the missing declarations from your example? 
> Thanks!

This suffices to reproduce:

```d
struct S{ int x; }
S s;
alias x = s.tupleof; // this works
alias y = s.tupleof[0]; // this is a compile error?!
```

The underlying issue is that `.tupleof` has some magic that is not 
accessible to aliases.

Consider:

```d
struct S{ int x; }
void main(){
     S s;
     alias x = s.tupleof;
     x[0] = 2; // ok
     alias y = s.x;
     y = 2; // error
}
```

So `x[0]` is an alias to the field of an instance.

I think all of these examples should just work.

When template parameters get involved however, local instantiation can 
get a bit tricky. So making it work without breakage probably also comes 
down to the issue that local instantiation works with only one context, 
which had a fix in DMD but was never ported to GDC and LDC, and was then 
reverted via deprecation in DMD as well. This is one of the most 
annoying and long-standing issues in D.


More information about the Digitalmars-d mailing list