Fix issue 17440: do not call .destroy on class instances in Nullable.nullify#6043
Fix issue 17440: do not call .destroy on class instances in Nullable.nullify#6043dlang-bot merged 4 commits intodlang:masterfrom
Conversation
std/typecons.d
Outdated
| void nullify()() | ||
| { | ||
| .destroy(_value); | ||
| static if (is(T == class)) |
There was a problem hiding this comment.
Should this be if (is(T == class) || is(T == interface)) ?
There was a problem hiding this comment.
You're right, I missed that. Fixed.
|
I don't think we can do this. There may be code bases relying on the fact that |
|
@MetaLang It seems unlikely, and in any case, the GC will collect the object eventually, if indeed there are no more references to it (if there's still another reference to it, then it's a bug to call the dtor, which is the complaint in issue 17440). |
wilzbach
left a comment
There was a problem hiding this comment.
I think we can do this - the spec never guaranteed deterministic calling of the the dtor for classes. OTOH object.destroy calls rt_finalize immediately, but that's a bug of nullify - it was never documented that it does so.
We should probably add a changelog entry so that it's visible to people.
|
Added changelog. |
Agree, I think most people expect it to work just like assigning a pointer or class ref to null. If they want deterministic destruction, they can destroy the object specifically, or use a scoped class. |
|
I don't agree but this is low on the list of things I care about. |
This is a reboot of #6038 with a simpler fix that doesn't require extensive, backward-incompatible changes to
Nullable.It does not take care of the problem of
Nullable!Classintroducing a second, inequivalent null state to a class reference.