Bug 18091 – "Error instantiating" cumulativeFold when passing a function inside another function
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-12-16T21:43:00Z
Last change time
2020-09-21T19:23:48Z
Assigned to
No Owner
Creator
mikey
Comments
Comment #0 by abc.mikey — 2017-12-16T21:43:00Z
DMD64 D Compiler v2.072.1
Best see with a test case:
import std.algorithm : cumulativeFold;
struct T {}
T t1(T a, int b) {
return T.init;
}
void main() {
auto arr = [0,1,1,0,0,0];
T t2(T a, int b) {
return T.init;
}
auto r1 = arr.cumulativeFold!( (a,b) => T.init )( T.init ); // no error
auto r2 = arr.cumulativeFold!t1( T.init ); // no error
//auto r3 = arr.cumulativeFold!t2( T.init ); // errors
}
Comment #1 by greeenify — 2017-12-24T20:05:12Z
This is an issue with delegates:
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(3377): Error: constructor onlineapp.main.cumulativeFold!(t2).cumulativeFoldImpl!(int[], T).cumulativeFoldImpl.Result.this cannot access frame of function D main
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(3412): Error: function onlineapp.main.cumulativeFold!(t2).cumulativeFoldImpl!(int[], T).cumulativeFoldImpl.Result.popFront cannot access frame of function D main
/dlang/dmd/linux/bin64/../../src/phobos/std/algorithm/iteration.d(3336): Error: template instance onlineapp.main.cumulativeFold!(t2).cumulativeFoldImpl!(int[], T) error instantiating
onlineapp.d(19): instantiated from here: cumulativeFold!(int[], T)
Run:
https://run.dlang.io/is/fh0WCC
Comment #2 by bugzilla — 2019-12-01T17:51:33Z
With the help of dustmite I got this down to:
template foo(T...)
{
static void bar()
{
T[0];
}
}
void main()
{
void t() {}
foo!t();
}
Don't know, if this helps anybody... The variadic argument seems to matter somehow.
Comment #3 by snarwin+bugzilla — 2020-09-21T19:23:48Z
*** This issue has been marked as a duplicate of issue 17841 ***