[Issue 9588] format prints context pointer for struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 7 19:18:52 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9588



--- Comment #6 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2013-03-07 19:18:48 PST ---
(In reply to comment #4)
> Hmm. Using __traits(allMembers, S) seems to indicate that the field name is
> 'this'. Since 'this' is a reserved keyword, that may be safer to check for than
> assuming that the compiler will always put it last.

This won't work out that easy. The code in format uses .tupleof to get to the
values, but .tupleof and allMembers return different results, for example:

void main()
{
    struct S { int x; this(int) { } }
}

allMembers:
tuple("x", "__ctor", "this")

.tupleof:
tuple(0, S(0).this)

So the indexes won't match. Since my new isNested trait was pulled, and
assuming the context pointer is last, I could do:

immutable tupleLen = val.tupleof.length;
foreach (i, e; val.tupleof)
{
    // skip printing context pointer
    static if (__traits(isNested, T) && i+i == tupleLen) { }
}

It's hard to tell whether this will be safe. 

Another idea is to change how .tupleof works internally (to remove exposing the
context pointer), but this might be a bad idea, serialization might probably
require it as well as other code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list