On 9/19/13 7:31 AM, Peter Alexander wrote:
On Thursday, 19 September 2013 at 13:55:54 UTC, monarch_dodra wrote:
I want to calculate the msb, and in the out contract, I want to
validate it is correct, by comparing it with what the input was.
In this case, this doesn't really work, since the input was "consumed".
Ok, so you need this v.old that I believe other languages have. I don't
think re-using v to mean the previous value of it would be a good idea.
It's useful sometimes to check the final value of v on function exit too.
Well I have bad news. Consider:
interface A
{
void fun(int x) out { assert(x == 42); }
}
class B : A
{
void fun(int x) { x = 42; }
}
void main()
{
A a = new B;
a.fun(0);
}
This fails at run time, meaning in this particular case x will have the
value before the call.
Andrei