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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 23 07:06:44 UTC 2024


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

--- Comment #4 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
The issue does not occur when lazy is replaced with an explicit delegate.

//////////////// test.d ////////////////
@safe:

void delegate() later;

void lazyFun(void delegate() @safe expr)
{
    later = { expr(); };
}

class C
{
    void virtualFunc() {}

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

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

--


More information about the Digitalmars-d-bugs mailing list