Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
July 23, 2007 [Issue 1364] New: 2.003 traits within loop | ||||
---|---|---|---|---|
| ||||
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 -- |
July 23, 2007 Re: [Issue 1364] New: 2.003 traits within loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | <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.. |
July 23, 2007 Re: [Issue 1364] New: 2.003 traits within loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | 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)))) |
July 24, 2007 [Issue 1364] 2.003 traits within loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1364 Daniel919@web.de changed: What |Removed |Added ---------------------------------------------------------------------------- BugsThisDependsOn| |1298 ------- Comment #2 from Daniel919@web.de 2007-07-24 09:55 ------- @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")))); ... This bug depends on #1298 -- |
September 03, 2007 [Issue 1364] 2.003 traits within loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1364 bugzilla@digitalmars.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #3 from bugzilla@digitalmars.com 2007-09-03 16:44 ------- 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. -- |
Copyright © 1999-2021 by the D Language Foundation