Thread overview
[Issue 2442] New: opApply does not allow inferring parameter types when overloaded on const
Nov 06, 2008
d-bugmail
Nov 06, 2008
d-bugmail
Jun 13, 2011
yebblies
Dec 26, 2011
Kenji Hara
Dec 27, 2011
Walter Bright
November 06, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2442

           Summary: opApply does not allow inferring parameter types when
                    overloaded on const
           Product: D
           Version: 2.019
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: schveiguy@yahoo.com


If I have the following code:

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

   int opApply(int delegate(ref const(int) v) dg) const
   {
      int result = 0;
      foreach(ref x; arr)
      {
        if(result = dg(x))
           break;
      }
      return result;
   }
}

This is a properly const-decorated struct.  I should be able to call
foreach(x; s)

Whether s is const or not.  However, the compiler currently gives me an error:

void main()
{
    S s;
    foreach(x; s)
    {
        x = 5;
    }
}

testit.d(32): Error: cannot uniquely infer foreach argument types


-- 

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





------- Comment #1 from schveiguy@yahoo.com  2008-11-06 09:34 -------
Note that this is a blocker for Tango


-- 

June 13, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=2442


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |yebblies@gmail.com


--- Comment #2 from yebblies <yebblies@gmail.com> 2011-06-13 12:08:24 PDT ---
https://github.com/D-Programming-Language/dmd/pull/120

-- 
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=2442


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Platform|x86                         |All
         OS/Version|Linux                       |All


--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2011-12-26 02:04:30 PST ---
New patch based on git master: 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=2442


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2011-12-26 16:40:26 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: -------