-
-
Notifications
You must be signed in to change notification settings - Fork 747
Fix issue 17440: do not call .destroy on class instances in Nullable.nullify #6043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
std/typecons.d
Outdated
| void nullify()() | ||
| { | ||
| .destroy(_value); | ||
| static if (is(T == class)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be if (is(T == class) || is(T == interface)) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.