[Issue 9588] format prints context pointer for struct
https://issues.dlang.org/show_bug.cgi?id=9588 Dlang Bot changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #9 from Dlang Bot --- dlang/phobos pull request #7307 "Fix Issue 9588 - format prints context pointer for struct" was merged into master: - 209dfd391589dd2e8e26c2999570bf38c368e0d5 by Bernhard Seckinger: Fix Issue 9588 - format prints context pointer for struct https://github.com/dlang/phobos/pull/7307 --
[Issue 9588] format prints context pointer for struct
https://issues.dlang.org/show_bug.cgi?id=9588 Dlang Bot changed: What|Removed |Added Keywords||pull --- Comment #8 from Dlang Bot --- @berni44 created dlang/phobos pull request #7307 "Fix Issue 9588 - format prints context pointer for struct" fixing this issue: - Fix Issue 9588 - format prints context pointer for struct https://github.com/dlang/phobos/pull/7307 --
[Issue 9588] format prints context pointer for struct
https://issues.dlang.org/show_bug.cgi?id=9588 Simen Kjaeraas changed: What|Removed |Added CC||simen.kja...@gmail.com --- Comment #7 from Simen Kjaeraas --- Another option: __traits(identifier, S.tupleof[1]) returns "this". --
[Issue 9588] format prints context pointer for struct
http://d.puremagic.com/issues/show_bug.cgi?id=9588 --- Comment #6 from Andrej Mitrovic andrej.mitrov...@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: ---
[Issue 9588] format prints context pointer for struct
http://d.puremagic.com/issues/show_bug.cgi?id=9588 hst...@quickfur.ath.cx changed: What|Removed |Added CC||hst...@quickfur.ath.cx --- Comment #2 from hst...@quickfur.ath.cx 2013-02-26 16:23:47 PST --- Is there a way to tell whether a field is the hidden context pointer? Does it have a specific name (that isn't compiler-dependent)? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 9588] format prints context pointer for struct
http://d.puremagic.com/issues/show_bug.cgi?id=9588 --- Comment #3 from Andrej Mitrovic andrej.mitrov...@gmail.com 2013-02-26 19:01:50 PST --- (In reply to comment #2) Is there a way to tell whether a field is the hidden context pointer? Does it have a specific name (that isn't compiler-dependent)? None that I know of, but it appears it's always the last member (at least in DMD). When we get the isNested[1] trait pulled we could simply do a test on the aggregate and just ignore the last field when writing its contents. [1]: https://github.com/D-Programming-Language/dmd/pull/1362 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 9588] format prints context pointer for struct
http://d.puremagic.com/issues/show_bug.cgi?id=9588 --- Comment #4 from hst...@quickfur.ath.cx 2013-02-26 20:19:22 PST --- 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 9588] format prints context pointer for struct
http://d.puremagic.com/issues/show_bug.cgi?id=9588 --- Comment #5 from Andrej Mitrovic andrej.mitrov...@gmail.com 2013-02-26 20:22:21 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. Nice catch. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---
[Issue 9588] format prints context pointer for struct
http://d.puremagic.com/issues/show_bug.cgi?id=9588 Andrej Mitrovic andrej.mitrov...@gmail.com changed: What|Removed |Added Summary|format prints null for|format prints context |struct functions|pointer for struct --- Comment #1 from Andrej Mitrovic andrej.mitrov...@gmail.com 2013-02-25 18:11:48 PST --- (In reply to comment #0) import std.string; import std.stdio; void main() { struct S { int x; bool empty() { return false; } } writeln( format(%s, S()) ); } S(0, null) It shouldn't try to print the function. I think this should also apply to property functions since e.g. empty is typically a property function. Oh wait a minute, I know what this is. It's the hidden context pointer. If you change the struct to 'static' the null disappears. But I don't think format() should print that. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email --- You are receiving this mail because: ---