With dmd 2.070.2:
struct S
{
struct Static
{
static:
int payload;
}
alias Static.payload this; // no identifier for declarator Static.payload
alias get this; // OK
ref @property get(){return Static.payload;}
}
Same error if Static is moved outside of S.
(This pattern is useful for grouping members and methods of S that shouldn't conflict with the symbol used with alias this).
Comment #1 by nick — 2016-04-12T11:20:11Z
Note: A normal alias for `get` also works (as a workaround) instead of the property line above:
alias get = Static.payload;
Comment #2 by nick — 2016-04-22T11:08:06Z
The pattern is probably more useful with named mixin members:
struct S
{
template T()
{
int i;
}
mixin T m;
//alias m.i this; //error
// workaround
alias get this;
alias get = m.i;
}
Comment #3 by razvan.nitu1305 — 2018-11-02T11:40:43Z
This enhancement request is invalid for 2 reasons:
1. Alias this is used for struct/class members. payload is not a member of struct S so the error you are getting is correct.
2. Alias this can be used only in conjunction with identifiers not dotExpressions of any kind [1]. Therefore this code is not going to pass the parsing phase.
Closing as invalid.
[1] https://dlang.org/spec/grammar.html#AliasThis