www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6782] New: inout-correct range is not iterable using foreach with type deduction inside non-inout function

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6782

           Summary: inout-correct range is not iterable using foreach with
                    type deduction inside non-inout function
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: schveiguy yahoo.com



13:07:02 PDT ---
This should compile:

struct range
{
    int *ptr;
     property inout(int)* front() inout
    {
        return ptr;
    }

     property bool empty() const
    {
        return ptr is null;
    }

    void popFront()
    {
        ptr = null;
    }
}

void main()
{
    int x = 5;
    auto r = range(&x);
    foreach(p; r) // line 24
    {
    }
}

bug.d(24): Error: variable bug.main.p inout variables can only be declared
inside inout functions
bug.d(24): Error: cannot implicitly convert expression (__r1.front()) of type
int* to inout(int)*

The range foreach rewrite somehow gets inout into the resulting type of
r.front, where it should really be the resulting wild type (in this case int*)

Changing the foreach loop to:

foreach(int *p; r)
{
}

compiles.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 07 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6782


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

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



https://github.com/D-Programming-Language/dmd/pull/439

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 07 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6782


Walter Bright <bugzilla digitalmars.com> changed:

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



16:26:38 PDT ---
https://github.com/D-Programming-Language/dmd/commit/28b39dece1fe6a4d5c82c7accd04ba380855dd11

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