On 7/1/2011 9:24 AM, Timon Gehr wrote:
All arguments given for a runtime check of this kind are the result of a
misunderstanding of contract inheritance. The 'in'-contract of an overridden
method merely extends the in-contract of the parent's method, and does not
override it. In that way, the compiler statically ensures that the precondition
of
a child cannot possibly fail if the parent's passed. Thats the sole reason for
the
short-circuiting behavior.
The child's contract says: If my parent's contract failed, I can still satisfy
the
postcondition, if this _alternative_ precondition holds. But it does not
necessarily have to pass on all input the parent passes on, because it does not
even get checked if the parent's precondition holds.
If you add such a check, the child's in-contract will have to carefully
duplicate
the parent's precondition in order not to provoke a nonsensical runtime-error.
Adding such a check would make D's contracts unusable in anything but the most
trivial cases.
(Analogously, the child's 'out'-contract does not have to re-check the parent's
postcondition.)
Right.