[Issue 6857] Precondition contract checks should be statically bound.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 4 05:33:58 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=6857
--- Comment #29 from Andrei Alexandrescu <andrei at metalanguage.com> 2012-05-04 05:35:12 PDT ---
(In reply to comment #28)
> > The literally FIRST hit takes to a slide deck, see http://goo.gl/544fU. There
> > there is theory and examples on how contracts work.
>
> Andrei, those slides don't address the issue at all.
The issue as exemplified herein is:
class A {
void foo(int x) in { assert(x > 0); } body {}
}
class B : A {
void foo(int x) in { assert(x > -2); } body {}
}
void fizzbuzz(A a) {
a.foo(-1);
}
The question is, why does the code work when A's contract is in fact violated.
Slide 22-10 in that deck gives as example a method invert(). The base class has
precondition epsilon >= 10^(– 6) and the derived class has precondition epsilon
>= 10^(– 20). The surrounding slides explain rather copiously how a call to
invert against the derived class works even though the precondition of the base
class is violated (e.g. by passing epsilon = 10^(– 10). The example given in
the slides has a straightforward correspondence to the one above.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list