Thread overview
[Issue 12265] Puritiy inference fails with passing template function as an alias?
Apr 18, 2014
Kenji Hara
May 16, 2021
Tomoya Tanjo
April 18, 2014
https://issues.dlang.org/show_bug.cgi?id=12265

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra@gmail.com

--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> ---
*** Issue 12410 has been marked as a duplicate of this issue. ***

--
April 18, 2014
https://issues.dlang.org/show_bug.cgi?id=12265

--- Comment #3 from monarchdodra@gmail.com ---
(In reply to Dmitry Olshansky from comment #0)
> Distilled from std.algorithm.sort and is a blocker for its purity inference.

Work around for sort: https://github.com/D-Programming-Language/phobos/pull/2075

--
May 16, 2021
https://issues.dlang.org/show_bug.cgi?id=12265

Tomoya Tanjo <ttanjo@gmail.com> changed:

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

--- Comment #4 from Tomoya Tanjo <ttanjo@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`
```

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

--- Comment #5 from dlangBugzillaToGithub <robert.schadek@posteo.de> ---
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18782

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB

--