Thread overview
[Issue 4880] New: [patch] std.range.put does not handle output ranges implement via opDispatch; breaks on RefAppender
Sep 17, 2010
Rob Jacques
Sep 17, 2010
David Simcha
Sep 17, 2010
Rob Jacques
Feb 15, 2012
Rob Jacques
September 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4880

           Summary: [patch] std.range.put does not handle output ranges
                    implement via opDispatch; breaks on RefAppender
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody@puremagic.com
        ReportedBy: sandford@jhu.edu


--- Comment #0 from Rob Jacques <sandford@jhu.edu> 2010-09-17 10:14:54 PDT ---
std.range.put does not correctly introspect types which implement put via opDispatch. This is fairly simple to fix by swapping hasMember out for a __traits compiles test.

void put(R, E)(ref R r, E e)
{
+    static if (__traits(compiles, {return R.init.put(E.init);})  )
-    static if (hasMember!(R, "put") ||
-    (isPointer!R && is(pointerTarget!R == struct) &&
-     hasMember!(pointerTarget!R, "put")))
    {

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


David Simcha <dsimcha@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dsimcha@yahoo.com


--- Comment #1 from David Simcha <dsimcha@yahoo.com> 2010-09-17 10:38:01 PDT ---
This is a rather problematic bug.  If we use your patch, it will break when uniform function call syntax is fully implemented.  I guess what we need is for hasMember to be less restrictive.  It should include opDispatch, and while we're at it, pointers to structs.

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



--- Comment #2 from Rob Jacques <sandford@jhu.edu> 2010-09-17 12:33:14 PDT ---
Well half of puts' functionality is to emulate uniform function call syntax for
structs and classes: i.e. re-write put(r,e) into r.put(e). So I'd expect UFC to
break put with or without this patch.

I had thought of improving hasMembers (either the __traits or templated version) to support opDispatch, however, I do not think that it is possible. The problem is template constraints. Consider the highly synthetic example:

  void opDispatch(string name, T...)
    if( name.length == T.length )  {}

Because the template constraint could be non-trivially dependent on something
more than name there's no way to check if r.opDispatch!"put" is valid without
actually evaluating r.put(e) (i.e. __traits(compiles,...))

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 09, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4880


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 15, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4880


Rob Jacques <sandford@jhu.edu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #3 from Rob Jacques <sandford@jhu.edu> 2012-02-14 20:49:21 PST ---
I converted the patch into a pull request:

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

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