www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1364] New: 2.003 traits within loop

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

           Summary: 2.003 traits within loop
           Product: D
           Version: 2.002
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: Daniel919 web.de


import std.stdio;

class D
{
    this() { }
    ~this() { }
    void foo() { }
    int foo(int) { return 0; }
    int x;
}

void main()
{
        D d = new D;

        foreach (t; __traits(allMembers, typeof(d)))
                writefln(typeid(typeof(__traits(getMember, d, t))));
}


(17): Error: string expected as second argument


-- 
Jul 23 2007
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
<d-bugmail puremagic.com> wrote in message 
news:bug-1364-3 http.d.puremagic.com/issues/...
 http://d.puremagic.com/issues/show_bug.cgi?id=1364
                writefln(typeid(typeof(__traits(getMember, d, t))));
Isn't that supposed to be __traits(getMember, d, "t") ? Which entirely makes sense given the error message..
Jul 23 2007
prev sibling next sibling parent BCS <ao pathlink.com> writes:
Reply to d-bugmail puremagic.com,

 http://d.puremagic.com/issues/show_bug.cgi?id=1364
 
 Summary: 2.003 traits within loop
 Product: D
 Version: 2.002
 Platform: PC
 OS/Version: Windows
 Status: NEW
 Severity: normal
 Priority: P2
 Component: DMD
 AssignedTo: bugzilla digitalmars.com
 ReportedBy: Daniel919 web.de
 import std.stdio;
 
 class D
 {
 this() { }
 ~this() { }
 void foo() { }
 int foo(int) { return 0; }
 int x;
 }
 void main()
 {
 D d = new D;
 foreach (t; __traits(allMembers, typeof(d)))
 writefln(typeid(typeof(__traits(getMember, d, t))));
 }
 (17): Error: string expected as second argument
 
The issue might be that the foreach is a run time foreach and the inner __traits needs a string literal. Some sort of array-to-tuple magic is needed. This might end up looing somthing like this: mixin(CTFEarrayToTuple(__traits(allMembers, typeof(d))))
Jul 23 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1364


Daniel919 web.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |1298





 Nazo Humei: On IRC I was told it should work.
The foreach should be "expanded" at compile time to:
writefln(typeid(typeof(__traits(getMember, d, "foo"))));
writefln(typeid(typeof(__traits(getMember, d, "x"))));
...




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


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID





The problem is that 't' is a runtime variable, not a string literal. When D
gets a static foreach, this kind of program will work.


-- 
Sep 03 2007