www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17571] New: Cannot create alias of __traits(getMember

https://issues.dlang.org/show_bug.cgi?id=17571

          Issue ID: 17571
           Summary: Cannot create alias of __traits(getMember
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: minor
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: shachar weka.io

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).

--
Jun 28 2017