[Issue 24720] Can't alias __traits(getMember)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 26 08:19:16 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24720
RazvanN <razvan.nitu1305 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |razvan.nitu1305 at gmail.com
Resolution|--- |DUPLICATE
--- Comment #1 from RazvanN <razvan.nitu1305 at gmail.com> ---
The issue has nothing to do with __traits(getMember). It's the alias that's the
problem:
struct T
{
void myFun(int x) {}
}
T instance;
void test()
{
alias fun = instance.myFun;
fun(10); // error: instance required
}
The problem is that you cannot alias an expression, only symbols or types. The
problem here seems to be that the fun alias is accepted, but the compiler
actually aliases to the T.myFun symbol which is not attached to any particular
symbol. Looking at the docs [1] I see that the last runnable line in the
example is commented (alias c = s.j) is commented out with a "scheduled for
deprecation" comment, so I assume that this was discussed at some point.
PS: this has been reported in the past multiple times:
https://issues.dlang.org/show_bug.cgi?id=6842 .
[1] https://dlang.org/spec/declaration.html#alias-variable
*** This issue has been marked as a duplicate of issue 6842 ***
--
More information about the Digitalmars-d-bugs
mailing list