D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18751 - chunkBy predicate cannot access local variable
Summary: chunkBy predicate cannot access local variable
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: 2018-04-09 23:57 UTC by hsteoh
Modified: 2024-12-13 18:58 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description hsteoh 2018-04-09 23:57:56 UTC
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)
-------
Comment 1 hsteoh 2018-04-10 00:04:55 UTC
https://github.com/dlang/phobos/pull/6441
Comment 2 hsteoh 2018-04-10 00:06:57 UTC
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.
Comment 3 hsteoh 2018-04-11 21:53:22 UTC
PR has been closed, as it has been decided this needs to be addressed in the compiler rather than the library.
Comment 4 dlangBugzillaToGithub 2024-12-13 18:58:18 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/19422

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB