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

Mathias Lang <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |[email protected]
                   |                            |m

--- Comment #1 from Mathias Lang <[email protected]> ---
This should have never worked to begin with!
Slightly modifying your example to expose the bug:

```
import core.stdc.stdio;

void foo()
{
    scope baseKey = Key.getKey();
}

int main(string[] argv)
{
    printf("main init\n");
    foo();
    printf("main exit\n");
    assert(Key.global !is null);
    return 0;
}

class Key
{
private:
    this() { printf("ctor\n"); }
    ~this() { printf("dtor\n"); }

    static Key global;
    static Key getKey() { return (global = new Key()); }
}
```

As you can see, in here the compiler has no way to know it *should* destroy
`baseKey` at the end of the `foo` function. And `scope` in this case is
misleading, as the `scope` reference is GC-allocated anyway.

--

Reply via email to