Contract programming

Oleg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 17 13:07:11 PST 2014


Is this behavior normal or it's bug?

[code]

import std.stdio;

class A
{
     float func( float x )
     in
     {
         assert( x > 0 );
         stderr.writeln( "A.func in block" );
     }
     body
     {
         stderr.writeln( "A.func body block" );
         return x / 3;
     }
}

class B : A
{
     override float func( float x )
     in
     {
         assert( x < 10 );
         stderr.writeln( "B.func in block" );
     }
     body
     {
         stderr.writeln( "B.func body block" );
         return x * 3;
     }
}

void main()
{
     auto a = new B;
     auto v = a.func( 3.14 );
}

[output]

A.func in block
B.func body block

In class B 'in' block not called, but if add 'out' block it 
called both for A and B classes.


More information about the Digitalmars-d-learn mailing list