digitalmars.D.bugs - [Issue 8027] New: in contract is never checked for overrided functions
- d-bugmail puremagic.com (54/54) May 03 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8027
- d-bugmail puremagic.com (12/12) May 03 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8027
- d-bugmail puremagic.com (13/13) May 03 2012 http://d.puremagic.com/issues/show_bug.cgi?id=8027
http://d.puremagic.com/issues/show_bug.cgi?id=8027 Summary: in contract is never checked for overrided functions Product: D Version: D2 Platform: x86_64 OS/Version: Linux Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: adam.chrapkowski gmail.com --- Comment #0 from Adam Chrapkowski <adam.chrapkowski gmail.com> 2012-05-03 14:11:30 PDT --- 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. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 03 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8027 timon.gehr gmx.ch changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |timon.gehr gmx.ch Resolution| |DUPLICATE --- Comment #1 from timon.gehr gmx.ch 2012-05-03 14:32:27 PDT --- *** This issue has been marked as a duplicate of issue 6856 *** -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 03 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8027 timon.gehr gmx.ch changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|DUPLICATE |INVALID --- Comment #2 from timon.gehr gmx.ch 2012-05-03 14:35:25 PDT --- 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.) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 03 2012