[Issue 13710] Invariants not enforced on methods from alias this
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Nov 11 06:16:33 PST 2014
https://issues.dlang.org/show_bug.cgi?id=13710
--- Comment #2 from Don <clugdbug at yahoo.com.au> ---
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.
--
More information about the Digitalmars-d-bugs
mailing list