On Saturday, 19 September 2020 at 18:48:31 UTC, Jacob Carlborg wrote:
A nested class seems to be able to escape the `this` reference:

Ahh, thanks.

I just realized that it can escape into other parameters without the `scope` qualifier?

This

class Bar
{
    void bar(scope Bar b) @safe pure
    {
        b = this;
    }
}

compiles but this

class Bar
{
    scope void bar(scope Bar b) @safe pure
    {
b = this; // Error: scope variable `this` assigned to `b` with longer lifetime
    }
}

fails as

foo.d(6,11): Error: scope variable `this` assigned to `b` with longer lifetime

Reply via email to