import std.stdio; class Foo { int foobar(int a, int b) in { assert (a > 0 && b > 0); writeln("Foo in"); } out(ret) { assert(ret > 0); writeln("Foo out"); } body { return a + b; } } class Bar : Foo { override int foobar(int a, int b) in { assert(a * b + 8 > 1); writeln("Bar in"); } out(ret) { assert (ret > 1); writeln("Bar out"); } body { return 2; } } void main() { try { auto _foo = new Bar(); _foo.foobar(1, 2); } catch (Exception e) { writeln(e); } } ______________________________________________________________________ IN contract for function Bar.foobar() is never checked. For me it makes sense (becuse in contracts must be checked by the caller which may not know anything about overriding function) but compiler should not allow to define IN contract for an overriding function.
*** This issue has been marked as a duplicate of issue 6856 ***
Oops, actually this is not a duplicate, it is just invalid. This is how precondition inheritance is supposed to work. (a>0 && b>0 suffices as a condition for the inheriting class to need to accept the input, therefore the additional in-contract is not even checked.)