[Issue 23923] `this` not captured by lazy expression

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 15 15:02:31 UTC 2024


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

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com

--- Comment #5 from RazvanN <razvan.nitu1305 at gmail.com> ---
Hmmm, there's seems to be a problem with the creation of the second delegate in
the original code (the first delegate is created when virtualFunc() is passed
to the lazy parameter). If the delegate is extracted directly, the context
pointer is preserved correctly:

//@safe:

void delegate() later;

void lazyFun(lazy void expr)
{
    later = &expr;
    //later = { expr; };
}

class C
{
    void virtualFunc() {}

    final void run()
    {
        lazyFun(virtualFunc());
    }   
}

void main()
{
    auto c = new C;
    c.run();
    later();
}

However, the code is not safe anymore.

--


More information about the Digitalmars-d-bugs mailing list