"Timon Gehr" <[email protected]> wrote in message
news:[email protected]...
> 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 I understand this correctly, you think the following code should be
perfectly valid:
class A { void func(uint x) in { assert(x < 10); } body {} }
class B : A { void func(uint x) in { assert(x == 50); } body {} }
If A.func can be called with any value 0..10, why is it legal to override it
with a function that can't accept these values? Can you give an example
where accepting input that is not a superset of the overriden function's
possible input is valid?