https://d.puremagic.com/issues/show_bug.cgi?id=12265

           Summary: Puritiy inference fails with passing template function
                    as an alias?
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from Dmitry Olshansky <[email protected]> 2014-02-26 
01:08:10 PST ---
Distilled from std.algorithm.sort and is a blocker for its purity inference.
Tested with DMD64 D Compiler v2.065-devel-671874e.

The test case:

// (things like this are introduced by binaryFun template)
bool cmp(T)(auto ref T a, auto ref T b)  { return a < b; }

template sortImpl(alias pred, R)
{
    void sort(R arr) //pure //fails to infer pure here
    {
        pred(arr[0], arr[1]);        
    }
}

T[] sorted(T)(T[] stuff)
{
    //this works as pure
    sortImpl!((a, b) => a < b, T[]).sort(stuff);
    //this doesn't
    sortImpl!(cmp, T[]).sort(stuff);
    return stuff;
}

void main() pure
{
    int[] a = [1, 8, 3, 16];
    a = sorted(a);
}

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

Reply via email to