D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14909 - Template argument of std.algorithm.iteration.chunkBy cannot access a local variable
Summary: Template argument of std.algorithm.iteration.chunkBy cannot access a local va...
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-08-12 07:49 UTC by Tomoya Tanjo
Modified: 2024-12-13 18:44 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tomoya Tanjo 2015-08-12 07:49:50 UTC
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 Dlang Bot 2020-09-10 19:11:02 UTC
@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 Dlang Bot 2020-09-23 01:05:20 UTC
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 Iain Buclaw 2021-08-23 14:11:51 UTC
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 dlangBugzillaToGithub 2024-12-13 18:44:08 UTC
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