When I redefine functions from D with "in" contracts, the inherited "in" contracts are checked. If they fail, then redefined "inside" contracts are checked. If I do not specify any contract, then it is interpreted as if there is an empty contract "in". Thus, the following code compiles and runs successfully.
module main;
import std.stdio;
interface I
{
void write( int i )
in
{
assert( i > 0 );
}
}
class C : I
{
void write( int i )
{
writeln( i );
}
}
int main()
{
I i = new C;
i.write( -5 );
getchar();
return 0;
}
I want the condition to be I.write()checked when I call I.write(), as this is what is known to be enough for the I.write()compiler to execute correctly. Checking all the preconditions after the dynamic dispatch amazes me as odd from the point of view of the TOE, since the encapsulation is lost.
in { assert( false ); } , , . D? ?