define in contract according to the caller, not the callee.

deadalnix deadalnix at gmail.com
Sun Feb 26 11:33:53 PST 2012


Le 26/02/2012 17:40, Timon Gehr a écrit :
> On 02/26/2012 05:26 PM, deadalnix wrote:
>> Everything start from this bug report :
>> http://d.puremagic.com/issues/show_bug.cgi?id=6856
>>
>> And the piece of code associated :
>>
>> import std.stdio;
>>
>> class A{
>> void foo()in{writeln("in!");}out{writeln("out!");}body{}
>> }
>> class B:A{
>> override void foo(){} // add in{assert(false);}body to get it working
>> }
>>
>> void main(){
>> A x = new A;
>> x.foo(); // in! \ out!
>> B y = new B;
>> y.foo(); // out!
>> }
>>
>> B.foo in contract isn't specified, so it is implicitly deduced that no
>> preconditions have to be checked.
>
> That is the wrong way to go about it. When would you want that? Removing
> the in-contract must be explicit. (in{}) Otherwise, the whole concept of
> contract inheritance is implemented in a bogus way. (The absence of a
> contract would be able to override the presence of another one and
> silence contract violations that might indicate serious bugs in the
> software.)
>

Using caller's place type to determine what is the in contract would 
really improve things on this problem.

All polymorphic uses of the type would still have to respect the contract.

Requiring an explicit "in {}" is something we should consider.


More information about the Digitalmars-d mailing list