This is bug or not? (immutable class containing struct with dtor)
Tejas
notrealemail at gmail.com
Fri Dec 17 18:02:52 UTC 2021
On Friday, 17 December 2021 at 18:01:03 UTC, Tejas wrote:
> On Friday, 17 December 2021 at 17:34:05 UTC, Denis Feklushkin
> wrote:
>> On Friday, 17 December 2021 at 17:27:53 UTC, Denis Feklushkin
>> wrote:
>>
>>> [...]
>>
>> ("serializer_bug" is just name of my local .d file)
>
> I think since `immutable` objects are kept in Read Only
> Storage, you can't call destructors on them since the objects
> don't get erased when `~this` is called, but rather they get
> assigned their `.init` value, which tells the GC that they can
> be collected.
>
> `immutable class` has nothing to do with it, even the following
> fails to compile:
> ```d
>
>
>
> struct S
> {
> ~this() immutable {}
> }
>
> void main()
> {
> S s = S();
> }
>
> Error: `immutable` method `onlineapp.S.~this` is not callable
> using a mutable object
> ```
Correction:
`immutable S s = S();` inside the `void main()`
More information about the Digitalmars-d-learn
mailing list