digitalmars.D.bugs - [Issue 1748] New: Wrong stringof for templated classes
- d-bugmail puremagic.com (25/25) Dec 23 2007 http://d.puremagic.com/issues/show_bug.cgi?id=1748
- d-bugmail puremagic.com (8/8) Nov 10 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1748
- d-bugmail puremagic.com (12/12) Nov 10 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1748
- Christopher Wright (1/1) Nov 11 2008 Scratch that. This isn't a straightforward fix.
- d-bugmail puremagic.com (9/9) Nov 15 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1748
- d-bugmail puremagic.com (6/6) Nov 15 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1748
- d-bugmail puremagic.com (12/12) Nov 15 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1748
- d-bugmail puremagic.com (19/19) Nov 23 2008 http://d.puremagic.com/issues/show_bug.cgi?id=1748
http://d.puremagic.com/issues/show_bug.cgi?id=1748 Summary: Wrong stringof for templated classes Product: D Version: unspecified Platform: Macintosh OS/Version: Mac OS X Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: csantander619 gmail.com I understand that "class A(T)" is syntactic sugar for "template A(T){class A...", but I still think this is wrong behavior: --- class A(T) {} alias A!(int) Aint; A!(int) a; pragma(msg, typeof(a).stringof); pragma(msg, Aint.stringof); static assert(typeof(a).stringof != "A", "typeof(a).stringof shouldn't be A"); --- Both pragmas print A, when I think it should be A!(int). Tested with GDC rev 198, but this is part of the front end. --
Dec 23 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1748 ------- Comment #1 from dhasenan gmail.com 2008-11-10 10:02 ------- This is really hurting me with CTFE + mixins. I can't use templated classes without creating a subclass for each template instantiation, and I can't use templated structs, if I want to use some of my testing code for mock objects. (That is, these objects cannot have methods that reference templated classes or templated structs.) --
Nov 10 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1748 ------- Comment #2 from dhasenan gmail.com 2008-11-10 13:35 ------- It looks like fixing this will require giving Dsymbol a reference to a TemplateInstance, eliminating the nesting part (or giving an option to omit it), then modifying *::toChars to check if it's in a template instance and, if so, prepend the template instance's string representation. You can add the reference at template.c:3026 Only types (typedefs, classes, structs) need modification in their toChars methods. Expected time required to make this change: 30-60 minutes. I'll make it tonight, if I can get llvm to compile. --
Nov 10 2008
Scratch that. This isn't a straightforward fix.
Nov 11 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1748 ------- Comment #3 from dhasenan gmail.com 2008-11-15 22:04 ------- This isn't a straightforward fix after all. I've seen some situations in which a string representation closer to what we would need is shown... With structs, I'm seeing: typeof(a).stringof prints the correct result A!(int).stringof prints the wrong result This will give at least a workaround with a minimum of effort. --
Nov 15 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1748 ------- Comment #4 from dhasenan gmail.com 2008-11-15 22:52 ------- Created an attachment (id=279) --> (http://d.puremagic.com/issues/attachment.cgi?id=279&action=view) Patch to add template parameters to class .stringof --
Nov 15 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1748 ------- Comment #5 from dhasenan gmail.com 2008-11-15 22:54 ------- If you have a templated struct, it partially works already: --- struct S(T) {} S!(int) s; pragma (msg, typeof(s).stringof); // prints S!(int) pragma (msg, S!(int).stringof); // prints S pragma (msg, (S!(int)).stringof); // prints S!(int) --- The patch I just added gives the same output if you change 'struct' to 'class'. --
Nov 15 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1748 ------- Comment #6 from dhasenan gmail.com 2008-11-23 08:43 ------- The patch I submitted fixes the case of: class S(T){} I don't think it fixes any other cases: class S(T) { class B {} } S!(int).B.stringof == B template Template(T) { struct S {} } Template!(int).S.stringof == S However, it does cover the basic case, which is something of an improvement. I'll see what I can do about everything else. Additionally, I think there might be something going on with nested template .stringof that I have to look into. --
Nov 23 2008