Bug 14909 – Template argument of std.algorithm.iteration.chunkBy cannot access a local variable

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-08-12T07:49:50Z
Last change time
2024-12-13T18:44:08Z
Assigned to
No Owner
Creator
Tomoya Tanjo
See also
https://issues.dlang.org/show_bug.cgi?id=18751, https://issues.dlang.org/show_bug.cgi?id=18753
Moved to GitHub: dmd#19025 →

Comments

Comment #0 by ttanjo — 2015-08-12T07:49:50Z
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
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