D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18470 - std.algorithm.splitter has frame access problems for custom preds
Summary: std.algorithm.splitter has frame access problems for custom preds
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2018-02-19 19:27 UTC by Seb
Modified: 2020-03-21 03:56 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 Seb 2018-02-19 19:27:19 UTC
This isn't an issue for the string binaryFuns as used in the examples, but their lambda variants fail:

---
void main()
{
    import std.algorithm;

    auto w = [[0], [1], [2]];
    assert(w.splitter!"a.front == b"(1).equal([[[0]], [[2]]]));
    
    assert(w.splitter!((a, b) => a.front == b)(1).equal([[[0]], [[2]]])); // fails
}
---

---
onlineapp.d(8): Error: template std.algorithm.iteration.splitter cannot deduce function from argument types !((a, b) => a.front == b)(int[][], int), candidates are:
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(3695):        std.algorithm.iteration.splitter(alias pred = "a == b", Range, Separator)(Range r, Separator s) if (is(typeof(binaryFun!pred(r.front, s)) : bool) && (hasSlicing!Range && hasLength!Range || isNarrowString!Range))
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(4000):        std.algorithm.iteration.splitter(alias pred = "a == b", Range, Separator)(Range r, Separator s) if (is(typeof(binaryFun!pred(r.front, s.front)) : bool) && (hasSlicing!Range || isNarrowString!Range) && isForwardRange!Separator && (hasLength!Separator || isNarrowString!Separator))
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(4264):        std.algorithm.iteration.splitter(alias isTerminator, Range)(Range input) if (isForwardRange!Range && is(typeof(unaryFun!isTerminator(input.front))))
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(4510):        std.algorithm.iteration.splitter(C)(C[] s) if (isSomeChar!C)
----


---
void main()
{
    import std.algorithm;
    import std.ascii : toLower;

    assert("abXcdxef".splitter!"a.toLower == b"('x').equal(["ab", "cd", "ef"]));
    assert("abXcdxef".splitter!((a, b) => a.toLower == b)('x').equal(["ab", "cd", "ef"]));
}
---


---
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(3726): Error: static function onlineapp.main.splitter!((a, b) => a.toLower == b, string, char).splitter.Result.lastIndexOf cannot access frame of function D main
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(3764): Error: function onlineapp.main.splitter!((a, b) => a.toLower == b, string, char).splitter.Result.front cannot access frame of function D main
onlineapp.d(8): Error: template instance onlineapp.main.splitter!((a, b) => a.toLower == b, string, char) error instantiating
---
Comment 1 basile-z 2018-05-26 03:08:58 UTC
Pull : https://github.com/dlang/phobos/pull/6522
Comment 2 github-bugzilla 2018-06-05 18:25:26 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/b5162ecc014a33b5866f2de62b5af012cf425c1d
fix issue 18470 - std.algorithm.splitter has frame access problems for custom preds

https://github.com/dlang/phobos/commit/a6bf2b6c4793f6af9f6aa148f6bf603b702fb942
Merge pull request #6522 from BBasile/issue-18470

fix issue 18470 - std.algorithm.splitter has frame access problems for custom preds
merged-on-behalf-of: Jack Stouffer <jack@jackstouffer.com>