Thread overview
[Issue 2443] New: opApply should allow delegates that are not ref if it makes no sense
Nov 06, 2008
d-bugmail
Nov 24, 2008
d-bugmail
Dec 26, 2011
Kenji Hara
Dec 27, 2011
Walter Bright
November 06, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2443

           Summary: opApply should allow delegates that are not ref if it
                    makes no sense
           Product: D
           Version: 2.019
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: schveiguy@yahoo.com


Currently, builtin arrays enjoy the restriction that you cannot ref the index parameter when doing a foreach:

int main(string[] args)
{
   foreach(ref i, ref s; args) // Error: foreach: key cannot be out or ref
   { }
}

But when trying to do something similar on a struct, the compiler cannot resolve the opApply:

struct S
{
    int[] arr;
    int opApply(int delegate(int i, ref int v) dg)
    {
        int result = 0;
        foreach(i, ref x; arr)
        {
            if((result = dg(i, x)) != 0)
                break;
        }
        return result;
    }
}

void main()
{
    S s;
    foreach(i, ref v; s)
    {}
}

emits:
testit.d(32): function testit.S.opApply (int delegate(int i, ref int v) dg)
does not match parameter types (int delegate(ref int __applyArg0, ref int v))
testit.d(32): Error: cannot implicitly convert expression (__foreachbody1) of
type int delegate(ref int __applyArg0, ref int v) to int delegate(int i, ref
int v)

This has implications for const as well, because it would make sense in S above to have an opApply WITHOUT a ref int for the value in the case of a const S.


-- 

November 24, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2443


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Severity|normal                      |enhancement
           Keywords|                            |spec




-- 

December 07, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2443


klickverbot@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |klickverbot@gmail.com


--- Comment #1 from klickverbot@gmail.com 2009-12-07 04:52:15 PST ---
This applies to D1 as well.

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


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2011-12-26 02:05:32 PST ---
https://github.com/D-Programming-Language/dmd/pull/581

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


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |FIXED


--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> 2011-12-26 16:40:59 PST ---
https://github.com/D-Programming-Language/dmd/commit/581ed237a077569d76b2658ffc24600db76aad25

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



--- Comment #4 from github-bugzilla@puremagic.com 2012-03-03 21:25:06 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/f4a653ad068abe8436bac8dedd597533515ed090 Merge pull request #474 from dsimcha/master

Remove Bug 2443 Workaround from InputRangeObject

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



--- Comment #5 from github-bugzilla@puremagic.com 2012-03-08 22:54:52 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/7b62989568958eaf610b0e80004f1e6358dc2b6b Get rid of Bug 2443 workaround in InputRangeObject.

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