Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template argument of std.algorithm.iteration.chunkBy cannot access a local variable #19025

Open
dlangBugzillaToGithub opened this issue Aug 12, 2015 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

Tomoya Tanjo (@tom-tan) reported this on 2015-08-12T07:49:50Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=14909

CC List

Description

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
}
---
@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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

@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 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

@dlangBugzillaToGithub
Copy link
Author

ibuclaw (@ibuclaw) commented on 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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant