The following code cannot be compiled.
I checked it by using DMD trunk (v2.068-devel-407dac3) in Mac OSX.
---
import std.algorithm.iteration;
void main()
{
auto n = 3;
auto s = [1,2,3].chunkBy!(a => a+n); /// Error: function sample.main.ChunkByImpl!(__lambda1, int[]).ChunkByImpl.__lambda12 cannot access frame of function D main
}
---
Comment #1 by dlang-bot — 2020-09-10T19:11:02Z
@jamesragray created dlang/phobos pull request #7625 "Issue 14909: Provided a fix for the forward range version of chunkBy …" mentioning this issue:
- Issue 14909: Provided a fix for the forward range version of chunkBy so that it can accept predicates refernce variables in the calling function
https://github.com/dlang/phobos/pull/7625
Comment #2 by dlang-bot — 2020-09-23T01:05:20Z
dlang/phobos pull request #7625 "Issue 14909: Provided a fix for the forward range version of chunkBy …" was merged into master:
- 2ed6952a719ce610bc3a513d67b602163f196ff9 by James Gray:
Issue 14909: Provided a fix for the forward range version of chunkBy so that it can accept predicates refernce variables in the calling function
https://github.com/dlang/phobos/pull/7625
Comment #3 by ibuclaw — 2021-08-23T14:11:51Z
Possibly reduced test:
---
template binaryFun(alias fun)
{
alias binaryFun = fun;
}
struct ChunkByImpl(alias pred, Range)
{
alias eq = binaryFun!((a, b) => pred(a));
Range r;
this(Range )
{
eq(r, r);
}
}
auto chunkBy(alias pred, Range)(Range)
{
ChunkByImpl!(pred, Range);
}
void main()
{
auto n = 3;
1.chunkBy!(a => a+n);
}
Comment #4 by robert.schadek — 2024-12-13T18:44:08Z