www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14788] New: Incorrect rejection of inout function call


          Issue ID: 14788
           Summary: Incorrect rejection of inout function call
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: k.hara.pg gmail.com
            Blocks: 14626

Following code does not compile, but it should.

auto make(K, V)(inout V[K] aa)
    static struct Result
        V[K] aa;
        ref front() inout { return aa[1]; }
    return inout Result(aa);

void main()
    int[int] aa = [1:1];
    make(aa).front();    // line 14


$ dmd -o- test
test.d(14): Error: modify inout to mutable is not allowed inside inout function


If the 'Result' struct is not static, the error is not wrong. Because the
returned reference by Result.front() may come from the local state of enclosing
'make' function.

However the 'Result' is actually static and it cannot access outer inout
function context. Therefore the compile error is not correct.

This compiler bug is blocking fix for the regression issue 14626.

Jul 08 2015