www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1386] New: "string expected" when using allMembers-element in __traits(getMember, ...)

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

           Summary: "string expected" when using allMembers-element in
                    __traits(getMember, ...)
           Product: D
           Version: 2.003
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jascha mainia.de


import std.stdio;

struct Temp(T...)
{
    alias void delegate(T) asdf;
}

class Asdf
{
    Temp!(uint) asdf;
    Temp!(string) qwer;
    Temp!(real,real) yxcv;
}

void main()
{
    foreach ( member; __traits(allMembers, Asdf) )
    {
        Asdf a;
        writefln("%s %s", member, typeid(typeof(__traits(getMember, a,
member))));
    }
}


-- 
Jul 30 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386





------- Comment #1 from samukha voliacable.com  2007-07-31 02:56 -------
__traits works only with strings known at compile time and in your example
'member' is evaluated at run-time. However, allMembers trait evaluates to an
array literal, so there should be a way to iterate through it at compile time.
Unfortunately, D doesn't have true 'static foreach' and you probably have to
resort to hacks.    


-- 
Jul 31 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386





------- Comment #2 from jascha mainia.de  2007-07-31 07:04 -------
'member' should be evaluated at compile-time, since foreach usually works with
CTFE. if not, the error should be "cannot evaluate ... at compile time".


-- 
Jul 31 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386


mrmocool gmx.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool gmx.de
           Severity|normal                      |blocker
            Version|2.003                       |2.027




-- 
Apr 01 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386





------- Comment #3 from mrmocool gmx.de  2009-04-01 13:25 -------
I've tried everything to work around this, but nothing worked.

In fact this prevents many thinkable uses of compile time introspection.


-- 
Apr 01 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386


dhasenan gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|2.027                       |2.003




------- Comment #4 from dhasenan gmail.com  2009-04-01 17:44 -------
Leave the version number on the _earliest_ dmd version exhibiting the problem.


-- 
Apr 01 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386


dhasenan gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |normal




------- Comment #5 from dhasenan gmail.com  2009-04-01 17:47 -------
Also, you can work around this using a for-loop (I think) or recursive
templates; and "blocker" refers to a bug sufficiently severe that Walter should
drop everything else and fix this bug, or even possibly roll back to an earlier
version that does not exhibit the bug.


-- 
Apr 01 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386





------- Comment #6 from mrmocool gmx.de  2009-04-01 17:54 -------
Ok, sorry didn't know.

Finally managed to compile a workaround:
template Sequence(size_t count, size_t index = 0)
{
        static if (index < count)
                alias Tuple!(index, Sequence!(count, index + 1)) Sequence;  
        else
                alias Tuple!() Sequence;
}

        static const members = __traits (allMembers, foo);
        foreach (i; Sequence!(members.length))
        {
                foreach (p; ParameterTypeTuple!(__traits(getMember, foo,
members[i])))
                        writefln(typeid(p));
        }


-- 
Apr 01 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386


Simen Kjaeraas <simen.kjaras gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |simen.kjaras gmail.com


--- Comment #7 from Simen Kjaeraas <simen.kjaras gmail.com> 2010-01-02 05:45:23
PST ---
As a way to index allMembers as a tuple, here's a template converting an array
known at compile time to a tuple:

template ArrayToTuple( alias Arr, U... ) {
    static if ( Arr.length ) {
        alias ArrayToTuple!( Arr[ 0..$-1 ], Arr[ $-1 ], U ) ArrayToTuple;
    } else {
        alias U ArrayToTuple;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 02 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386



--- Comment #8 from Hoenir <mrmocool gmx.de> 2010-02-02 17:02:30 PST ---
allMembers returns a tuple now (svn r360) but this still doesn't work. Yields a
strange error.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 02 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1386


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #9 from Don <clugdbug yahoo.com.au> 2011-04-15 21:33:24 PDT ---
The error message is:
test2.d(22): Error: no property '__T4TempTkZ' for type 'test2.Asdf'
Some kind of junk tuple members are being included in allMembers.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 15 2011