D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18091 - "Error instantiating" cumulativeFold when passing a function inside another function
Summary: "Error instantiating" cumulativeFold when passing a function inside another f...
Status: RESOLVED DUPLICATE of issue 17841
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-12-16 21:43 UTC by mikey
Modified: 2020-09-21 19:23 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description mikey 2017-12-16 21:43:00 UTC
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 Seb 2017-12-24 20:05:12 UTC
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 berni44 2019-12-01 17:51:33 UTC
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 Paul Backus 2020-09-21 19:23:48 UTC

*** This issue has been marked as a duplicate of issue 17841 ***