www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5877] New: Cannot 'alias __traits(parent, obj) X;'

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5877

           Summary: Cannot 'alias __traits(parent, obj) X;'
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: kennytm gmail.com



Since the introduction of __traits(parent) in commit 2e261cd6, it is possible
that the __traits expression returns a type. However, the parser does not
recognize this in an alias statement, and rejects the code.

--------------------------------------------------------
class B {
    int x();
    alias __traits(parent, x) S;
    static assert(is(B == S));
}
--------------------------------------------------------
x.d(3): basic type expected, not __traits
x.d(3): no identifier for declarator int
x.d(3): semicolon expected to close alias declaration
x.d(3): Declaration expected, not '__traits'
--------------------------------------------------------

A workaround is to create an existing expression that returns a type:

--------------------------------------------------------
class B {
    int x();
    alias typeof(__traits(parent, x).init) S;
    static assert(is(B == S));
}
--------------------------------------------------------

But it is better the __traits work without these hacks.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 23 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5877


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Cannot 'alias               |Cannot treat
                   |__traits(parent, obj) X;'   |'__traits(parent, obj)' as
                   |                            |a type



The same applies anywhere that expects a type, e.g.

    template (alias m, T = __traits(parent, m)) {
    //                     ^^^^^^^^^^^^^^^^^^^

       __traits(parent, m) s;
    // ^^^^^^^^^^^^^^^^^^^

etc.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 24 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5877


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |DUPLICATE



15:42:43 PST ---
*** This issue has been marked as a duplicate of issue 7804 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 10 2012