Thread overview
[Issue 10608] New: std.typecons.RefCounted has very poor diagnostics
Jul 11, 2013
Andrej Mitrovic
Sep 19, 2013
Andrej Mitrovic
Sep 19, 2013
Kenji Hara
July 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10608

           Summary: std.typecons.RefCounted has very poor diagnostics
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-07-11 05:06:19 PDT ---
Example 1, passing too many arguments to the ctor:

-----
import std.typecons;

struct S
{
    this(int x, int y)
    {
        _data = typeof(_data)(x, y);
    }

    struct T
    {
        this(int x)
        {
        }
    }

    RefCounted!T _data;
}

void main() { }
-----

$ dmd test.d
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\conv.d(3673): Error: static assert  (2u == 1u) is false
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(3362):        instantiated from here: emplace!(T, int, int)
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(3412):        instantiated from here: initialize!(int, int)
> test.d(9):        instantiated from here: __ctor!(int, int)

Example 2, passing too few arguments to the ctor:

-----
import std.typecons;

struct S
{
    this(int x)
    {
        _data = typeof(_data)(x);
    }

    struct T
    {
        this(int x, int y)
        {
        }
    }

    RefCounted!T _data;
}

void main() { }
-----

$ dmd test.d
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\conv.d(3676): Error: cannot implicitly convert expression (_param_1) of type int to T
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(3362): Error: template instance std.conv.emplace!(T, int) error instantiating
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(3412):        instantiated from here: initialize!(int)
test.d(9):        instantiated from here: __ctor!(int)
> C:\dmd-git\dmd2\windows\bin\..\..\src\phobos\std\typecons.d(3412): Error: template instance std.typecons.RefCounted!(T).RefCounted.RefCountedStore.initialize!(int) error instantiating
> test.d(9):        instantiated from here: __ctor!(int)
> test.d(9): Error: template instance std.typecons.RefCounted!(T).RefCounted.__ctor!(int) error instantiating

Example 3, accessing uninitialized payload:

-----
import std.typecons;

struct S
{
    void test()
    {
        assert(_data.x == 1);
    }

    struct Payload
    {
        int x;
    }

    RefCounted!(Payload, RefCountedAutoInitialize.no) _data;
}

void main()
{
    S s;
    s.test();
}
-----

$ dmd test.d
> core.exception.AssertError@std.typecons(3507): Assertion failure

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10608


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody@puremagic.com        |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-09-18 18:10:22 PDT ---
The first two diagnostics have improved since they're now emitted in emplace. The third one is fixed in the pull.

https://github.com/D-Programming-Language/phobos/pull/1586

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10608



--- Comment #2 from github-bugzilla@puremagic.com 2013-09-18 20:35:34 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/401ded61c82e7dbff38b94a44bc5fa3d092baacc Fix Issue 10608 - Better diagnostic for RefCounted assert.

https://github.com/D-Programming-Language/phobos/commit/1c8a49a989e2654a5375ae414d9927f8f35a0da6 Merge pull request #1586 from AndrejMitrovic/Fix10608

Issue 10608 - Better diagnostic for RefCounted assert.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 19, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10608


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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