Bug 16179 – [REG2.072] git HEAD: multiSort no longer callable with delegate with context
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-06-17T10:11:00Z
Last change time
2016-10-01T11:46:56Z
Assigned to
gruen_tobias
Creator
dlang-bugzilla
Comments
Comment #0 by dlang-bugzilla — 2016-06-17T10:11:33Z
//////// test.d ////////
import std.algorithm;
void main()
{
int[] arr;
int n;
arr.multiSort!(
(a, b) => a > b,
(a, b) => a < n,
);
}
////////////////////////
Introduced in https://github.com/dlang/phobos/pull/4235
Comment #1 by dlang-bugzilla — 2016-06-17T10:14:08Z
Forgot the error messages:
.../std/algorithm/sorting.d(922): Error: static function test.main.multiSort!((a, b) => a > b, (a, b) => a < n).multiSort!(int[]).multiSort.predFun cannot access frame of function D main
.../std/algorithm/sorting.d(923): Error: static function test.main.multiSort!((a, b) => a > b, (a, b) => a < n).multiSort!(int[]).multiSort.predFun cannot access frame of function D main
.../std/algorithm/sorting.d(895): Error: static function test.main.multiSortImpl!((a, b) => a > b, (a, b) => a < n).multiSortImpl cannot access frame of function D main
.../std/algorithm/sorting.d(913): Error: static function test.main.multiSortImpl!((a, b) => a < n).multiSortImpl cannot access frame of function D main
.../std/algorithm/sorting.d(900): Error: template instance test.main.multiSortImpl!((a, b) => a < n) error instantiating
.../std/algorithm/sorting.d(927): instantiated from here: multiSortImpl!((a, b) => a > b, (a, b) => a < n)
test.d(7): instantiated from here: multiSort!(int[])
Comment #2 by john.loughran.colvin — 2016-08-18T12:37:22Z
Here's a subtly different example that doesn't actually access the frame, but the compiler says it does:
import std.algorithm : multiSort;
struct N
{
string p;
string q;
}
auto foo(N[] t)
{
t.multiSort!((u, v) => u.q < v.q,
(u, v) => u.p < v.p);
}
with a similar error message:
phobos/std/algorithm/sorting.d(897): Error: static function blah.foo.multiSortImpl!((u, v) => u.q < v.q, (u, v) => u.p < v.p).multiSortImpl cannot access frame of function blah.foo
phobos/std/algorithm/sorting.d(915): Error: static function blah.foo.multiSortImpl!((u, v) => u.p < v.p).multiSortImpl cannot access frame of function blah.foo
phobos/std/algorithm/sorting.d(902): Error: template instance blah.foo.multiSortImpl!((u, v) => u.p < v.p) error instantiating
phobos/std/algorithm/sorting.d(929): instantiated from here: multiSortImpl!((u, v) => u.q < v.q, (u, v) => u.p < v.p)
blah.d(11): instantiated from here: multiSort!(N[])
note that the error message also exhibits https://issues.dlang.org/show_bug.cgi?id=16401 so it's possible this is actually a compiler bug
Comment #3 by gruen_tobias — 2016-08-19T22:24:30Z
There is a fix.
The nested static functions have to be moved out of the multiSort function (maybe as private module members), then it works.
Comment #4 by github-bugzilla — 2016-08-26T19:47:58Z