Making alias of a struct field needs "this".
Basile B.
b2.temp at gmx.com
Tue Jun 2 09:07:08 UTC 2020
On Tuesday, 2 June 2020 at 08:56:13 UTC, realhet wrote:
> Hello,
>
> I have a 2 level nested struct structure with nice descriptive
> field names.
> And I thought it will be easy to alias those identifierLists
> with a few letter names and do some calculations on them.
> But I'm having an error.
>
> struct A{
> struct B{ int c; }
> B b;
>
> auto f(){
> alias d = b.c;
> return d; //Compiler Error: need 'this' for c of type int.
> }
> }
>
> There's the this and it's called "b."
>
> Why is this? If I copy paste the aliased expression "b.c", it
> compiled fine.
>
> Thanks in advance!
There's a language rule, expressions cant be aliased, however D
has a bug, some expressions
that look like type can be aliased, then when you use them you
have an error about 'this' but in first place here you should
really have an error saying 'cant alias expression'.
More information about the Digitalmars-d-learn
mailing list