On Sun, 18 Oct 2009 03:44:39 -0400, Rainer Deyke <rain...@eldwood.com>
wrote:
Andrei Alexandrescu wrote:
Rainer Deyke wrote:
The expression may mutate stuff.
It shouldn't. It's an error if it does, just like it's an error for an
assertion or post/precondition to have any side effects.
It would be nice if the compiler could catch this error, but failing
that, 'old' expressions are still no worse than assertions in this
respect.
I'm coming into this a little late, but what Rainer is saying makes sense
to me.
Would it help to force any access to the object to be treated as if the
object is const? i.e.:
old(this.x)
would be interpreted as:
(cast(const(typeof(this))this).x
and cached in the input contract section.
It seems straightforward that Rainer's solution eliminates the boilerplate
code of caching values available in the in contract, and if you force
const access, prevents calling functions which might mutate the state of
the object. But it uses the correct contract -- this object is not
mutable for this call only. I agree pure is too restrictive, because then
the object must be immutable, no?
Incidentally, shouldn't all access to the object in the in contract be
const by default anyways?
-Steve