[Issue 7517] New: Interface contracts broken

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Feb 16 06:18:15 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7517

           Summary: Interface contracts broken
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: renezwanenburg at gmail.com


--- Comment #0 from Rene Zwanenburg <renezwanenburg at gmail.com> 2012-02-16 06:18:13 PST ---
interface I {

  void enable()
  in  { assert(!enabled); }
  out { assert( enabled); }

  void disable()
  in  { assert( enabled); }
  out { assert(!enabled); }

  @property bool enabled() const;

}

class C : I {
  void enable() {
    _enabled = true;
  }

  void disable() {
    _enabled = false;
  }

  @property bool enabled() const {
    return _enabled;
  }

  bool _enabled;
}

void foo() {
  I i = new C;
  i.enable();
}


enable's in contract is not being called. After setting _enabled to true an
exception is thrown saying C does not implement opCmp(). 

When removing the out contract from the interface, or the disable() function
from the interface and implementation (even though it's never being used
anywhere in the application), the code will run without exceptions but the
contracts will still not be called.

-- 
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