digitalmars.D - stringof Bug?
- Janice Caron (18/18) Oct 19 2007 Do we count this as a bug, or not?
- Don Clugston (3/13) Oct 19 2007 There are quite a few stringof bugs. I think this one hasn't been report...
- Janice Caron (3/4) Oct 19 2007 Not at the time, but I have now. Surprisingly, it compiles! (What's
- Don Clugston (13/19) Oct 19 2007 Now that's an interesting question...
- 0ffh (5/7) Oct 19 2007 I can second that. I remember once I had a templated struct and
- Don Clugston (5/12) Oct 19 2007 I think you're right. It also seems to be right-associative, so a.b.c.d ...
- 0ffh (5/6) Oct 19 2007 You mean like the lexer finds "23.stringof" and then
Do we count this as a bug, or not? class T(int N) { } writefln(T!(1).stringof); This writes "T", not "T!(1)". This might seem trivial, but it took me hours to debug a problem I had, whereby I was passing a load of type names into a mixin and then using stringof to turn that input into valid D code, so of course when I did mixin M(T!(1)); it all fell over. The error message was something like "class T(int) used as a type", and the location of the error was deep inside the mixin. After much aggravation, I found the workaround, which was was to do class A : T!(1) {} mixin M(A); So, is that a real bug, or are my expectations just too high?
Oct 19 2007
Janice Caron wrote:Do we count this as a bug, or not? class T(int N) { } writefln(T!(1).stringof); This writes "T", not "T!(1)".So, is that a real bug, or are my expectations just too high?There are quite a few stringof bugs. I think this one hasn't been reported before. BTW, did you try typeof(T!(1)).stringof ?
Oct 19 2007
BTW, did you try typeof(T!(1)).stringof ?Not at the time, but I have now. Surprisingly, it compiles! (What's the type of a type?) It prints "void".
Oct 19 2007
Janice Caron wrote:Now that's an interesting question... I've found that sticking typeof() in these sorts of things sometimes gives you useful information.BTW, did you try typeof(T!(1)).stringof ?Not at the time, but I have now. Surprisingly, it compiles! (What's the type of a type?)It prints "void".Hmm. 'void' frequently seems to be returned in lieu of a compile error. typeof(a) is always void when a is an alias. Something I've noticed is that x.stringof and (x).stringof are completely different. So (T!(1)).stringof is something else I'd try. In some of the early releases, .stringof behaved very differently; it performed semantic analysis on the expression, and returned a Lisp-y mass of parentheses. Did you know that .stringof was originally an Easter egg? (One of many <g>). It was documented in the spec, but not listed in the change log. IIRC, Walter said that it was too buggy to announce.
Oct 19 2007
Don Clugston wrote:Something I've noticed is that x.stringof and (x).stringof are completely different. So (T!(1)).stringof is something else I'd try.I can second that. I remember once I had a templated struct and needed sizeof. "(StructT!(int)).sizeof" worked for me while the "StructT!(int).sizeof" didn't. Maybe "." binds closer than "!"? Regards, Frank
Oct 19 2007
0ffh wrote:Don Clugston wrote:I think you're right. It also seems to be right-associative, so a.b.c.d ALWAYS parses as a.(b.(c.d)). 1.23.stringof doesn't work (that's in Bugzilla).Something I've noticed is that x.stringof and (x).stringof are completely different. So (T!(1)).stringof is something else I'd try.I can second that. I remember once I had a templated struct and needed sizeof. "(StructT!(int)).sizeof" worked for me while the "StructT!(int).sizeof" didn't. Maybe "." binds closer than "!"?
Oct 19 2007
Don Clugston wrote:1.23.stringof doesn't work (that's in Bugzilla).You mean like the lexer finds "23.stringof" and then it cannot make any sense of the "1." in front of it? Wouldn't happen with a packrat parser... ;-) Regards, Frank
Oct 19 2007