-
-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6043 from quickfur/issue17440b
Fix issue 17440: do not call .destroy on class instances in Nullable.nullify merged-on-behalf-of: Steven Schveighoffer <schveiguy@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| `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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters