[Issue 6856] New: Preconditions are not inherited
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Oct 26 13:59:26 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6856
Summary: Preconditions are not inherited
Product: D
Version: D2
Platform: Other
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: timon.gehr at gmx.ch
--- Comment #0 from timon.gehr at gmx.ch 2011-10-26 13:58:18 PDT ---
Precondition inheritance does not work in a satisfying way:
import std.stdio;
class A{
void foo()in{writeln("in!");}out{writeln("out!");}body{}
}
class B:A{
override void foo(){} // add in{assert(false);}body to get it working
}
void main(){
A x = new A;
x.foo(); // in! \ out!
B y = new B;
y.foo(); // out!
}
If the child class does not specify an in contract on an overriding method, the
in contract of the parent should be inherited, without adding a contract that
always passes. The current behavior makes it too easy to inadvertently widen
the interface and have undetected bugs. Chapter 10.9 in TDPL does not
explicitly mention the fact that it is supposed to work that way, but it seems
to assume it.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list