Bug 1364 – 2.003 traits within loop

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2007-07-23T04:52:00Z
Last change time
2015-06-09T01:04:59Z
Assigned to
bugzilla
Creator
Daniel919
Depends on
1298

Comments

Comment #0 by Daniel919 — 2007-07-23T04:52:42Z
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
Comment #1 by lovesyao — 2007-07-23T12:35:20Z
Reply to [email protected], > 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: [email protected] > ReportedBy: [email protected] > 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))))
Comment #2 by Daniel919 — 2007-07-24T09:55:55Z
@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
Comment #3 by bugzilla — 2007-09-03T16:44:02Z
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.