www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20502] New: Converting std.typecons.RefCounted!T to a string

https://issues.dlang.org/show_bug.cgi?id=20502

          Issue ID: 20502
           Summary: Converting std.typecons.RefCounted!T to a string gives
                    T's storage location instead of T's fields when T is a
                    struct without an explicit toString
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: minor
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: n8sh.secondary hotmail.com

Converting std.typecons.RefCounted!T to a string gives T's storage location
instead of T's fields when T is a struct without an explicit toString.

Demonstration:

---
void main()
{
    import std.typecons : refCounted;
    import std.stdio : writeln;

    writeln(123); // "123"
    writeln(refCounted(123)); // "123"

    struct A { string toString() { return "a"; } }
    writeln(A.init); // "a"
    writeln(refCounted(A.init)); // "a"

    // This one doesn't match:
    struct B { int x; }
    writeln(B(123)); // "B(123)"
    writeln(refCounted(B(123))); // "RefCounted!(B,
cast(RefCountedAutoInitialize)0)(RefCountedStore(558C7FFBC660))"
}
---

--
Jan 13