www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1748] New: Wrong stringof for templated classes

reply d-bugmail puremagic.com writes:
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1748






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
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1748






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
parent Christopher Wright <dhasenan gmail.com> writes:
Scratch that. This isn't a straightforward fix.
Nov 11 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1748






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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1748






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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1748






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
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1748






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