[Issue 6857] Precondition contract checks should be statically bound.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 3 13:43:24 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=6857



--- Comment #17 from deadalnix <deadalnix at gmail.com> 2012-05-03 13:44:36 PDT ---
(In reply to comment #15)
> fizbuzzA(A a) {
>     a.foo(); // A.foo's in contract is valid
> }
> 
> If an instance of B is passed to fizbuzzA, then the a.foo() will call B.foo(),
> and either A.foo's in contract or B.foo's in contract must be valid.
> 
> There is no error or invalid corner case here.
> 
> I suspect that you think the contracts are checked based on static typing -
> they are not, they are done using the virtual type.

We are all well aware that the behavior you describe is the current behavior.
However we do think it is not optimal and can be improved because of the corner
case mentioned.

As you can see in given code, fizbuzzA is an invalid piece of code waiting to
explode in your face. And this is what you want to avoid, why we use so much
stuff like contracts and unit tests (and, as far as I am concerned in my
professional work, code review and static analysis tools).

The later the bug is discovered, the more expansive it is to fix, and, if it
goes in production, the more damage it can do. We want to avoid as much as we
can the risk of having a piece of code waiting to explode deep in the codebase.

fizzbuzzA is the typical example of the function that will cost you quite a
lot. It is flawed, and waiting to crash the application at any moment. We want
to detect that ASAP, and in contract should tell us that ASAP.

-- 
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