[Issue 6857] Precondition contract checks should be statically bound.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 9 09:54:11 PDT 2012


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



--- Comment #76 from yebblies <yebblies at gmail.com> 2012-07-10 02:54:06 EST ---
(In reply to comment #55)
> 
> Unfortunately, I do not currently see a reasonable way of implementing this.
> Fortunately, as is it does not inhibit correct programs, it only accepts some
> invalid ones.

I can't see any way to do it without changing the abi for virtual functions
with contracts.
But, if changing the abi was ok, I think something like this would work:

class A
{
   void func(..., __in_contract_ptr)
   {
      void __nested_in_contract_A_func() { ... }
      auto __in_contract = &__nested_in_contract_A_func;
      __in_contract.ptr = ptr;
      __in_contract();
      ...
   }
}

class B : A
{
   void func(..., __in_contract_ptr)
   {
      void __nested_in_contract_B_func() { ... }
      auto __in_contract = &__nested_in_contract_B_func;
      __in_contract.ptr = ptr;
      __in_contract();
      ...
   }
}

void main()
{
   B b = new B();
   b.func(..., &__nested_in_contract_B_func.ptr);
   A a = b;
   a.func(..., &__nested_in_contract_A_func.ptr);
}

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