www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8027] New: in contract is never checked for overrided functions

reply d-bugmail puremagic.com writes:
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



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
next sibling parent d-bugmail puremagic.com writes:
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



*** 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
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8027


timon.gehr gmx.ch changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|DUPLICATE                   |INVALID



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