T.init, struct destructors and invariants - should they be called?

FeepingCreature feepingcreature at gmail.de
Sun Nov 18 15:15:11 UTC 2018


On Sunday, 18 November 2018 at 14:54:05 UTC, Stanislav Blinov 
wrote:
> On Sunday, 18 November 2018 at 14:47:51 UTC, FeepingCreature 
> wrote:
>> On Sunday, 18 November 2018 at 14:38:09 UTC, Stanislav Blinov 
>> wrote:
>>> @safe unittest {
>>>     Nullable!S a; // Look ma, no assert!
>>> }
>>
>> a = S(new Object); // Look pa, assert!
>
> That has to do with poor implementation of that example 
> Nullable, not the union. opAssign should check for _hasValue.

Right, which means you end up with moveEmplace in opAssign, which 
is the current Nullable implementation. Which only works because 
union{} essentially functions as a semi-official backdoor in the 
typesystem, even in @safe. https://run.dlang.io/is/YAnVBV

Is that *really* good language design, though?


More information about the Digitalmars-d mailing list