phobos/changelog/nullable-class.dd
2018-01-17 13:09:48 -08:00

27 lines
742 B
Text

`Nullable!C.nullify` no longer calls .destroy when `C` is a class or interface
Previously, when `.nullify` is called on a `Nullable!C` where `C` is a class or
interface, the underlying object is destructed immediately via the `.destroy`
function. This led to bugs when there are still references to the object
outside of the `Nullable` instance:
------
class C
{
int canary = 0xA71FE;
~this()
{
canary = 0x5050DEAD;
}
}
auto c = new C;
assert(c.canary == 0xA71FE);
Nullable!C nc = nullable(c);
nc.nullify;
assert(c.canary == 0xA71FE); // This would fail
------
The `.nullify` method has been fixed so that it no longer calls `.destroy` on
class or interface instances, and the above code will now work correctly.