The relationship of invariants and alias this

Mark Isaacson via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 11 01:21:30 PST 2014


On Tuesday, 11 November 2014 at 08:18:36 UTC, angel wrote:
> Wait !
> "x.value -= 100;" would call the invariant ?
> Alias this only rewrites your expression:
> "x -= 100;" becomes "x.value -= 100;"
> No method is called. Then there is no reason (is there ?) to 
> call the invariant.
> If you would create getter/setter properties ...

Intriguing - thanks :). Looks like you found the reason for the 
current implementation; what you've written is the "lowering" of 
alias this. From a semantic perspective though, we are claiming 
that "value *is* this"; there is an IsA relationship and I'd 
argue that the invariant should still apply because we are 
modifying "this", in a way.

I totally see where you're coming from though; that's why I 
wanted to open the floor for discussion as to what the more 
desirable behavior is.


More information about the Digitalmars-d mailing list