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 } ---
@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
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
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); }
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19025 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB