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

chunkBy predicate cannot access local variable #19422

Open
dlangBugzillaToGithub opened this issue Apr 9, 2018 · 3 comments
Open

chunkBy predicate cannot access local variable #19422

dlangBugzillaToGithub opened this issue Apr 9, 2018 · 3 comments

Comments

@dlangBugzillaToGithub
Copy link

hsteoh reported this on 2018-04-09T23:57:56Z

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

Description

Code:
-------
unittest
{
    import std.algorithm.comparison : equal;
    import std.algorithm.iteration : chunkBy;

    string[] data = [ "abc", "abc", "def" ];
    int[] indices = [ 0, 1, 2 ];

    auto chunks = indices.chunkBy!((i, j) => data[i] == data[j]);
    assert(chunks.equal!equal([ [ 0, 1 ], [ 2 ] ]));
}
-------

Compiler output:
-------
/usr/src/d/phobos/std/algorithm/iteration.d(1761): Error: function test.__unittest_L9_C1.ChunkByImpl!(__lambda1, int[]).ChunkByImpl.Group.popFront cannot access frame of function test.__unittest_L9_C1
/usr/src/d/phobos/std/range/primitives.d(884): Error: template instance `std.range.primitives.isInputRange!(Group)` error instantiating
/usr/src/d/phobos/std/algorithm/iteration.d(1781):        instantiated from here: isForwardRange!(Group)
-------
@dlangBugzillaToGithub
Copy link
Author

hsteoh commented on 2018-04-10T00:04:55Z

https://github.com/dlang/phobos/pull/6441

@dlangBugzillaToGithub
Copy link
Author

hsteoh commented on 2018-04-10T00:06:57Z

This is related to issue #14909, but the PR only fixes this problem, not that one, so I'm keeping the bug reports separate for now.

@dlangBugzillaToGithub
Copy link
Author

hsteoh commented on 2018-04-11T21:53:22Z

PR has been closed, as it has been decided this needs to be addressed in the compiler rather than the library.

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