On Thursday, 19 September 2013 at 06:39:09 UTC, Ivan Kazmenko
wrote:
On Thursday, 19 September 2013 at 01:41:15 UTC, mrd wrote:
$ ./bug
body, value=2
out contract, value=0
Why argument "value" in contract isn't equal 2 ?
Why should it be? value is a mutable argument, and the out
contract evaluates it at the return point, which is after it's
set to 0. It is no different than using value in the body just
before the return point.
If you want to preserve the original arguments until the return
point, use const and create a mutable duplicate.
Ivan Kazmenko.
I actually asked about this on the main threads:
http://forum.dlang.org/thread/gdmwjyrefhreghznb...@forum.dlang.org
I actually disagree though: How the function is implemented
should have no bearing on how the output contract should be
implemented. Both should get their own copy of the args. The
implementation of a function should not have to create a local
duplicate just because it happens to know that it has an out
contract.
This is particularly relent since (in theory), an in/out contract
should appear in a function's interface, and compiled/called by
client code (though that's not the case today).