Shortcut evaluation for hierarchy of in contracts

bearophile bearophileHUGS at lycos.com
Thu Jun 30 03:43:51 PDT 2011


Jens Mueller:

> unittest {
>     class Base {
>         void foo(uint i)
>             in { assert(i <= 10); }
>         body { }
>     }
>     
>     class Sub : Base {   
>         override void foo(uint i)
>             in { assert(i <= 5); } // fails to require less but I won't know
>         body
>         {
>             assert(i <= 5); // fails here because in contract wasn't checked
>         }
>     }
>     
>     auto s = new Sub;
>     //s.foo(10); // fails as expected
>     s.foo(7); // due to shortcut evaluation of in contracts this call passes all contracts
> }

I think it's a DMD bug, fit for Bugzilla if not already present.

Bye,
bearophile


More information about the Digitalmars-d mailing list