www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7401] New: Pure contracts Unnecessarily strict

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

           Summary: Pure contracts Unnecessarily strict
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: rtcvb32 yahoo.com



---
The compiler complaining to me that my function isn't 'pure' by calling a
non-pure function, specifically to!string(). 

However the unpure functions used are only accessed in the contracts (and only
if it failed). The contracts shouldn't be considered as part of the pure
contract. This is because they are totally excluded during the release builds
(and shouldn't have any side effects anyways).



Error: pure function 'offset' cannot call impure function 'to'  


struct X
{
    int size;

...

    const pure int offset(int field)
    out(o)
    {
        assert(o >= 0, "Negative value! Check structure:" ~ to!string(size) ~
"\n");
    }
    body { ... } 
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7401


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



See also issue 7224  (that asks kind of the opposite)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7401




---

 See also issue 7224  (that asks kind of the opposite)
In his remark, it seems rather silly. Of course it won't raise an exception when it's in release mode, the in contract won't even be present. However with the pure contract, I don't want to have to encompass a debug{} block to show my assert details. Then I need the -debug flag on as well otherwise it won't be checked, unless you go around it... in { string message = "use -debug or pure gets in the way"; debug { message = to!string(); } assert(something, x); } or in { debug { assert(something, "with message"); } assert(something); //same assert as above but doesn't give a useful message. } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 30 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7401




I think the right solution for this problem is to wait for  to!string(int)  to
become pure.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2012