digitalmars.D.learn - Multiple destructors
- Alex Biscotti (34/34) May 26 2023 Hello everyone! While researching the phobos library, I
- Ernesto Castellotti (2/10) May 26 2023 This is a bug to me, you should open an issue on bugzilla
- Alex Biscotti (3/14) May 26 2023 Do you mean that it's a bug in the documentation or
- Ernesto Castellotti (2/18) May 26 2023 Bug in the implementation of Mixin Template
- Alex Biscotti (3/22) May 26 2023 Hmm, this feature is used in Phobos in
- Ernesto Castellotti (7/32) May 26 2023 Currently the spec says "If the name of a declaration in a mixin
- Alex Biscotti (3/10) May 26 2023 Thank you for the clarification. I'll try to open an issue on
- Basile B. (39/46) May 26 2023 This is not a compiler bug, mixin templates are allowed to
Hello everyone! While researching the phobos library, I discovered that a class can have multiple destructors if the destructors are added via mixin injection. Accordingly, the question is whether a description of such feature should be added to the documentation, since the current description is a bit confusing - ["There can be only one destructor per class"](https://dlang.org/spec/class.html#destructors)? Here's a code demo of what I'm talking about: ```d import std; mixin template AddNewDtor() { ~this() { writeln("Mixin dtor"); } } class Foo { ~this() { writeln("Class dtor"); } mixin AddNewDtor; } void main() { { auto s = scoped!Foo; // prints `Mixin dtor` // prints `Class dtor` } } ```
May 26 2023
On Friday, 26 May 2023 at 09:07:07 UTC, Alex Biscotti wrote:Hello everyone! While researching the phobos library, I discovered that a class can have multiple destructors if the destructors are added via mixin injection. Accordingly, the question is whether a description of such feature should be added to the documentation, since the current description is a bit confusing - ["There can be only one destructor per class"](https://dlang.org/spec/class.html#destructors)? [...]This is a bug to me, you should open an issue on bugzilla
May 26 2023
On Friday, 26 May 2023 at 09:11:47 UTC, Ernesto Castellotti wrote:On Friday, 26 May 2023 at 09:07:07 UTC, Alex Biscotti wrote:Do you mean that it's a bug in the documentation or implementation of the language?Hello everyone! While researching the phobos library, I discovered that a class can have multiple destructors if the destructors are added via mixin injection. Accordingly, the question is whether a description of such feature should be added to the documentation, since the current description is a bit confusing - ["There can be only one destructor per class"](https://dlang.org/spec/class.html#destructors)? [...]This is a bug to me, you should open an issue on bugzilla
May 26 2023
On Friday, 26 May 2023 at 09:17:34 UTC, Alex Biscotti wrote:On Friday, 26 May 2023 at 09:11:47 UTC, Ernesto Castellotti wrote:Bug in the implementation of Mixin TemplateOn Friday, 26 May 2023 at 09:07:07 UTC, Alex Biscotti wrote:Do you mean that it's a bug in the documentation or implementation of the language?Hello everyone! While researching the phobos library, I discovered that a class can have multiple destructors if the destructors are added via mixin injection. Accordingly, the question is whether a description of such feature should be added to the documentation, since the current description is a bit confusing - ["There can be only one destructor per class"](https://dlang.org/spec/class.html#destructors)? [...]This is a bug to me, you should open an issue on bugzilla
May 26 2023
On Friday, 26 May 2023 at 09:24:29 UTC, Ernesto Castellotti wrote:On Friday, 26 May 2023 at 09:17:34 UTC, Alex Biscotti wrote:Hmm, this feature is used in Phobos in [std.signal](https://github.com/dlang/phobos/blob/master/std/signals.d#L259). Actually, this is how I found it, since I implemented the Signal functionality, but without garbage collection. It seems to me that this is an undocumented feature, rather than a bug.On Friday, 26 May 2023 at 09:11:47 UTC, Ernesto Castellotti wrote:Bug in the implementation of Mixin TemplateOn Friday, 26 May 2023 at 09:07:07 UTC, Alex Biscotti wrote:Do you mean that it's a bug in the documentation or implementation of the language?Hello everyone! While researching the phobos library, I discovered that a class can have multiple destructors if the destructors are added via mixin injection. Accordingly, the question is whether a description of such feature should be added to the documentation, since the current description is a bit confusing - ["There can be only one destructor per class"](https://dlang.org/spec/class.html#destructors)? [...]This is a bug to me, you should open an issue on bugzilla
May 26 2023
On Friday, 26 May 2023 at 09:39:29 UTC, Alex Biscotti wrote:On Friday, 26 May 2023 at 09:24:29 UTC, Ernesto Castellotti wrote:Currently the spec says "If the name of a declaration in a mixin is the same as a declaration in the surrounding scope, the surrounding declaration overrides the mixin one", I understand why this occurs with the current implementation, but either way the implementation should be changed or the specs should be clarified to explain this specific behavior with destructors.On Friday, 26 May 2023 at 09:17:34 UTC, Alex Biscotti wrote:Hmm, this feature is used in Phobos in [std.signal](https://github.com/dlang/phobos/blob/master/std/signals.d#L259). Actually, this is how I found it, since I implemented the Signal functionality, but without garbage collection. It seems to me that this is an undocumented feature, rather than a bug.On Friday, 26 May 2023 at 09:11:47 UTC, Ernesto Castellotti wrote:Bug in the implementation of Mixin TemplateOn Friday, 26 May 2023 at 09:07:07 UTC, Alex Biscotti wrote:Do you mean that it's a bug in the documentation or implementation of the language?Hello everyone! While researching the phobos library, I discovered that a class can have multiple destructors if the destructors are added via mixin injection. Accordingly, the question is whether a description of such feature should be added to the documentation, since the current description is a bit confusing - ["There can be only one destructor per class"](https://dlang.org/spec/class.html#destructors)? [...]This is a bug to me, you should open an issue on bugzilla
May 26 2023
On Friday, 26 May 2023 at 09:49:21 UTC, Ernesto Castellotti wrote:Currently the spec says "If the name of a declaration in a mixin is the same as a declaration in the surrounding scope, the surrounding declaration overrides the mixin one", I understand why this occurs with the current implementation, but either way the implementation should be changed or the specs should be clarified to explain this specific behavior with destructors.Thank you for the clarification. I'll try to open an issue on bugzilla.
May 26 2023
On Friday, 26 May 2023 at 09:07:07 UTC, Alex Biscotti wrote:Hello everyone! While researching the phobos library, I discovered that a class can have multiple destructors if the destructors are added via mixin injection. Accordingly, the question is whether a description of such feature should be added to the documentation, since the current description is a bit confusing - ["There can be only one destructor per class"](https://dlang.org/spec/class.html#destructors)?This is not a compiler bug, mixin templates are allowed to introduce a dtor; observe the output of ```d import std; mixin template AddNewDtor() { ~this() { writeln("Mixin dtor"); } } class Foo { ~this() { writeln("Class dtor"); } mixin AddNewDtor; } void main() { { Foo s = new Foo; writeln("-- dtor effect --"); s.__dtor; } { Foo s = new Foo; writeln("-- xdtor effect --"); s.__xdtor; } writeln("-- auto generated destruction... --"); } ``` as you can see, the internal `__xdtor` function is designed to call the two destructors, while `__dtor` only the "normal one", i.e the one that 's not mixed in. This is more a documentation bug IMO.
May 26 2023