Automatic invariant generation

Nicholas Wilson via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 7 07:31:42 PDT 2017


On Friday, 7 July 2017 at 14:17:34 UTC, Jonathan M Davis wrote:
> What does it even do?

asserts that the this pointer is not null, apparently which is 
annoying because you'd crash anyway. I suppose you might get a 
nicer error message but it doesn't add much.

> I don't see how it makes any sense for _anything_ to have an 
> invariant if it's not explicitly declared.

Worse I can't even @disable it because thats a syntax error.

> And honestly, I'm of the opinion that invariants with structs 
> are borderline useless, because they're run even before 
> opAssign, meaning that if you ever need to use = void; or use 
> emplace, then you're screwed if you have an invariant, because 
> it's bound to fail due to the object not having been 
> initialized previously.

Huh, I didn't know that. That does seems to be purpose defeating 
zealotry.

>Unfortunately, I couldn't get Walter to
> agree that it made sense to not call the invariant prior to 
> opAssign being called - which is why SysTime no longer has an 
> invariant (it was blowing up in people's code due to emplace 
> IIRC). As such, it seems that much more stupid for structs to 
> get any kind fo invariant automatically.
>
> - Jonathan M Davis


More information about the Digitalmars-d mailing list