www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4720] New: contracts don't work on function definitions

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4720

           Summary: contracts don't work on function definitions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mrmocool gmx.de



The Matlab C headers provide some kind of hand-crafted contracts by defining
extra functions with suffix "_d" that check all the arguments and then
detouring the calls to the original functions via the preprocessor (#define foo
foo_d)

I tried to leverage D's built-in contract programming but it doesn't work:

module externcontracts;
import externcontracts2;
void foo(int a) in {assert(a>=0);}

module externcontracts2;
void foo(int a){}

yields:
externcontracts.d(3): Error: function externcontracts.foo in and out contracts
require function body
resp.
externcontracts.d(3): missing body { ... } after in or out
if you put a ';' after the in{} block


Note that this is exactly the same syntax as for interface contracts.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 24 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4720


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 24 2010
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4720


Andrei Alexandrescu <andrei erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei erdani.com



PST ---
What is the expected use and effect of the code show? (Not sure I'm getting
it.) With or without contracts, externcontracts.foo and externcontracts2.foo
are distinct functions, so automatic forwarding from one another won't happen.

One obvious workaround would be:

module externcontracts;
import externcontracts2;
void foo(int a) in {assert(a>=0);} { return externcontracts2.foo(a); }

which may be automated in a number of ways (introspection, mixin etc).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 08 2013