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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 7 13:07:50 PDT 2011


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 at puremagic.com
        ReportedBy: schveiguy at yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy at yahoo.com> 2011-10-07 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: -------


More information about the Digitalmars-d-bugs mailing list