This is bug or not? (immutable class containing struct with dtor)

Tejas notrealemail at gmail.com
Fri Dec 17 18:36:39 UTC 2021


On Friday, 17 December 2021 at 18:32:43 UTC, Denis Feklushkin 
wrote:
> On Friday, 17 December 2021 at 18:02:52 UTC, Tejas wrote:
>
> I improved your sample:
>
> ```d
> immutable struct S
> {
>     ~this() {}
> }
>
> immutable struct S2
> {
>     S sss;
>     ~this() {}
> }
>
> void main()
> {
>     S2 s = S2();
> }
> ```
>
> ```
> Error: `immutable` method `serializer_bug.S.~this` is not 
> callable using a mutable object
> Error: mutable method `serializer_bug.S2.~this` is not callable 
> using a `immutable` object
> serializer_bug.d(17,5):        Consider adding `const` or 
> `inout` here
> ```
>
> immutable dtor can't be called at all?

Nope, seems to go against the very promise it's making

Labelling `~this()` as const or immutable means it won't affect 
the state of the object, but it will, by it's very nature.

That's why I said it's not too much of a stretch to imagine why 
they're disallowed entirely.


More information about the Digitalmars-d-learn mailing list