Thread overview
[Issue 7401] New: Pure contracts Unnecessarily strict
Jan 30, 2012
Era Scarecrow
Jan 30, 2012
Era Scarecrow
January 30, 2012
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


--- Comment #0 from Era Scarecrow <rtcvb32@yahoo.com> 2012-01-30 14:23:53 PST ---
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: -------
January 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7401


bearophile_hugs@eml.cc changed:

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


--- Comment #1 from bearophile_hugs@eml.cc 2012-01-30 14:43:21 PST ---
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: -------
January 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7401



--- Comment #2 from Era Scarecrow <rtcvb32@yahoo.com> 2012-01-30 14:55:06 PST ---
(In reply to comment #1)
> 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: -------
January 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7401



--- Comment #3 from bearophile_hugs@eml.cc 2012-01-30 15:07:54 PST ---
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: -------