Bug 17571 – Cannot create alias of __traits(getMember, ...)
Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-06-29T05:28:54Z
Last change time
2018-03-13T07:28:11Z
Assigned to
No Owner
Creator
Shachar Shemesh
Comments
Comment #0 by shachar — 2017-06-29T05:28:54Z
Consider the following program:
import unistd = core.sys.posix.unistd;
alias func = __traits(getMember, unistd, "write");
When trying to compile:
test.d(3): Error: basic type expected, not __traits
test.d(3): Error: semicolon expected to close alias declaration
test.d(3): Error: declaration expected, not '__traits'
Since unistd.write is a function, there is no reason for me not to be able to create an alias of it.
The only reason I'm marking this as a minor issue is because there is a workaround:
import unistd = core.sys.posix.unistd;
import std.meta;
alias func = Alias!(__traits(getMember, unistd, "write"));
This, however, goes outside the definition of what std.meta.Alias was meant for. It was meant for aliasing non-aliasable objects, not for aliasing functions (which is what is happening in this case).
Comment #1 by dlang-bugzilla — 2017-06-29T12:52:00Z