[Issue 12265] Puritiy inference fails with passing template function as an alias?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun May 16 04:53:35 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=12265

Tomoya Tanjo <ttanjo at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ttanjo at gmail.com

--- Comment #4 from Tomoya Tanjo <ttanjo at gmail.com> ---
The above code does not work yet but it is due to a non-eponymous template
rather than passing function as an alias parameter.

Here is a reproducible code (also in https://run.dlang.io/is/DErgFM):

```dlang
// eponymous template: infer pure
template sortImpl1(alias pred, R)
{
    void sortImpl1(R arr)
    {
        pred(arr[0], arr[1]);        
    }
}

// non-eponymous template: failed to infer pure
template sortImpl2(alias pred, R)
{
    void sort(R arr)
    {
        pred(arr[0], arr[1]);        
    }
}

void main() pure
{
    int[] a = [1, 8, 3, 16];
    sortImpl1!((a, b) => a < b, int[])(a);
    sortImpl2!((a, b) => a < b, int[]).sort(a); // line 23
}
```

I obtained the following error message:
```
onlineapp.d(23): Error: `pure` function `D main` cannot call impure function
`onlineapp.main.sortImpl2!((a, b) => a < b, int[]).sort`
```

--


More information about the Digitalmars-d-bugs mailing list