[Issue 1866] New: Couple of reflection bugs (.stringof)
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Feb 24 15:04:24 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1866
Summary: Couple of reflection bugs (.stringof)
Product: D
Version: 1.022
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: onlystupidspamhere at yahoo.se
I marked these as bugs. Some of them are very painful for reflection. Others
cannot be found from the specification. Yes I know there exists super funky
__traits in d2, but why can't these work too? At least they need to be
mentioned in the specs.
template tuple(T...) { alias T tuple; }
struct foo(A) {
int a;
tuple!(int,int) b;
foo2 c;
}
enum foo2 : ubyte { A }
template ident(T) {
pragma(msg, '"' ~ T.stringof ~ '"');
alias T ident;
}
template print(T...) { alias int print; }
template print2(T, int n = 0) {
static if (n < T.tupleof.length) {
pragma(msg, T.tupleof[n].stringof);
alias print2!(T, n+1) print2;
} else
alias int print2;
}
alias foo!(int) bar;
// BUG1:: inside ident(T) "foo!(int) " <- note the extra space
// BUG2:: .stringof returns "struct foo", this value is only returned on rare
cases like this
pragma(msg, '"' ~ ident!(bar).stringof ~ '"');
// BUG3:: inside ident(T) "ubyte" <- not the enum name, just the base type
(mentioned already elsewhere)
// BUG4:: .stringof returns "enum foo", this value is only returned on rare
cases like this
pragma(msg, '"' ~ ident!(foo2).stringof ~ '"');
// returns "tuple(((foo!(int) ).a),((foo!(int) )._b_field_0),((foo!(int)
)._b_field_1),((foo!(int) ).c),((foo!(int) ).d))"
// BUG1:: the extra space again after struct type
// BUG5:: extra parentheses around the struct type, second parentheses around
every member
// BUG6:: the _membername_field_num isn't in lang specification (would be much
easier if tuples could nest, sigh)
pragma(msg, '"' ~ bar.tupleof.stringof ~ '"');
// BUG7:: Error: tuple is not a valid template value argument (the tuple here
is some unspecified type that cannot be expressed in D)
// pragma(msg, '"' ~ print!(bar.tupleof).stringof ~ '"');
// returns:
// (foo!(int) ).a
// (foo!(int) )._b_field_0
// (foo!(int) )._b_field_1
// ubyte
// BUG8:: .stringof returns again base type name, not the field name for enums
unlike in .tupleof.stringof
alias print2!(bar) baz;
--
More information about the Digitalmars-d-bugs
mailing list