[Issue 9685] Context pointer of struct isn't copied when a closure is passed by alias

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Feb 16 06:52:59 PST 2015


https://issues.dlang.org/show_bug.cgi?id=9685

John Colvin <john.loughran.colvin at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |john.loughran.colvin at gmail.
                   |                            |com

--- Comment #1 from John Colvin <john.loughran.colvin at gmail.com> ---
Apparently this is a the same bug, see
http://forum.dlang.org/post/crhogpikareipbtyswhu@forum.dlang.org

import std.stdio;
struct MapResult(alias fun)
{
    @property int front() {return fun();}
    @property auto save() {return typeof(this)();}
}
void main()
{
    int ys_length = 4;
    auto dg = {return MapResult!({return ys_length;})();};
    writeln(dg().front); /* 4, correct */
    writeln(dg().save.front); /* garbage */
}

--


More information about the Digitalmars-d-bugs mailing list