Bug 8027 – in contract is never checked for overrided functions
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-05-03T14:11:00Z
Last change time
2012-05-03T14:35:25Z
Assigned to
nobody
Creator
adam.chrapkowski
Comments
Comment #0 by adam.chrapkowski — 2012-05-03T14:11:30Z
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.
Comment #1 by timon.gehr — 2012-05-03T14:32:27Z
*** This issue has been marked as a duplicate of issue 6856 ***
Comment #2 by timon.gehr — 2012-05-03T14:35:25Z
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.)