Shortcut evaluation for hierarchy of in contracts
Daniel Murphy
yebblies at nospamgmail.com
Fri Jul 1 09:56:47 PDT 2011
"Timon Gehr" <timon.gehr at gmx.ch> wrote in message
news:iuksb8$15l0$1 at digitalmars.com...
> 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?
More information about the Digitalmars-d
mailing list