On 7/3/11 1:16 AM, Timon Gehr wrote:
Andrei Alexandrescu wrote:
On 7/1/11 6:32 PM, Robert Jacques wrote:
No. I think the current behavior is correct. In fact, if anything, D
shouldn't allow you to define an in contract on any override method. A
Sub is a Base and therefore must be able to handle all inputs that are
valid for a Base.
That is a sensible enhancement.
Andrei
How so? The child class should still be able to take more general inputs than
the
parent: by specifying an in contract on an override method.
How would you reach that goal otherwise?
Timon
In any case, I consider the current implementation buggy, as having no
in contract in the superclass is different from having an empty in
contract there:
---
class Foo {
void baz(int i) {}
}
class Bar : Foo {
override void baz(int i) in {
assert(i < 5, "I am triggered, but should not be.");
} body {
assert(i < 5, "I should be triggered instead of the contract.");
}
}
void main() {
auto bar = new Bar;
bar.baz(6);
}
---
David