[Issue 8027] New: in contract is never checked for overrided functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 3 14:10:16 PDT 2012


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 at puremagic.com
        ReportedBy: adam.chrapkowski at gmail.com


--- Comment #0 from Adam Chrapkowski <adam.chrapkowski at 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: -------


More information about the Digitalmars-d-bugs mailing list