Skip to content

Conversation

@quickfur
Copy link
Member

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!Class introducing a second, inequivalent null state to a class reference.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @quickfur!

Bugzilla references

Auto-close Bugzilla Description
17440 Nullable.nullify() resets referenced object

@quickfur quickfur changed the title Fix issue 17440: do not call .destroy on class instances in .nullify Fix issue 17440: do not call .destroy on class instances in Nullable.nullify Jan 17, 2018
std/typecons.d Outdated
void nullify()()
{
.destroy(_value);
static if (is(T == class))
Copy link
Member

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)) ?

Copy link
Member Author

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.

@MetaLang
Copy link
Member

I don't think we can do this. There may be code bases relying on the fact that nullify will call destroy on objects.

@quickfur
Copy link
Member Author

@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).

Copy link
Contributor

@wilzbach wilzbach left a 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.

@quickfur
Copy link
Member Author

Added changelog.

@schveiguy
Copy link
Member

but that's a bug of nullify

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.

@dlang-bot dlang-bot merged commit 0666fc6 into dlang:master Jan 18, 2018
@MetaLang
Copy link
Member

I don't agree but this is low on the list of things I care about.

@quickfur quickfur deleted the issue17440b branch January 19, 2018 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants