https://issues.dlang.org/show_bug.cgi?id=13710

--- Comment #2 from Don <[email protected]> ---
I think there is still a problem. Does it actually make sense to have a class
invariant, when you have an alias this?

It seems as though having an 'alias this' is like exposing a public member
variable: once you do this, the class invariant cannot be trusted to be true at
all times.
I feel uneasy about this; it suggests that 'alias this' is bad practice.

It may be worth adding to the documentation at
http://dlang.org/contracts.

That states:
"Invariants are used to specify characteristics of a class or struct that
always must be true (except while executing a member function)."

I think that section should explicitly state that direct modification of
members in a way which violates the invariant, will not be detected until a
member function is called.

--

Reply via email to