www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - keyword: invariant

reply "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
According to the documentation only classes might contain "invariant".

Dmd-0.104 allows "invariant" in structs and checks those contracts.
test case:
svn://svn.kuehne.cn/dstress/nocompile/invariant_04.d

Dmd-0.104 allows "invariant" in unions and checks those contracts.
test case:
svn://svn.kuehne.cn/dstress/nocompile/invariant_06.d

The documentation doesn't forbid the usage of a class function named
"_invariant". The function will not be handled as a "invariant" contract,
that's correct.
The problem is that it's mangled name will conflict with "invariant".
test case:
svn://svn.kuehne.cn/dstress/run/invariant_11.d

Code:



























The Child's invariant[1] will be called before "y=5" [2] is executed.
It seems that not only inherited the Child it's Parent's invariant
but so did the Parent with the Child's invariant.
I think this is a bug and not a hole in the documentation.
Reason: This way contracts for new class members can't easily be added to a
sub-class.

test cases:
svn://svn.kuehne.cn/dstress/run/invariant_1[45].d

Thomas
Oct 22 2004
parent "Thomas Kuehne" <thomas-dloop kuehne.cn> writes:
in addition:

the invariant of a class that has got no own constructor is _not_ called after
the super
constructor finished.
test case:
svn://svn.kuehne.cn/dstress/run/invariant_18.d

Thomas
Oct 23 2004