On Monday, 26 August 2013 at 06:14:02 UTC, Ali Çehreli wrote:
On 08/25/2013 05:16 AM, deadalnix wrote:
> The problem is that invariant are checked at the
beginning/end on public
> function calls. As a consequence, it is impossible to use any
public
> method in an invariant.
That's a very interesting observation. Could the solution be
running the invariant only once, at the outermost public
function call? Hm... It would have to be a runtime feature
then, right? Every public function would have calls to the
invariant but those calls would have to be elided at runtime. I
think...
No need for runtime check :D
We simply need to add invariant check in the caller, not the
callee, and not introduce them if the caller is itself subject to
invariant insertion when called.
Here is another interesting observation: It is acceptable and
quite normal that the object is in limbo state during a public
member function. As a consequence, any function that operates
on the object must use the object in a write-only fashion
during that time frame. This is true even for non-member
functions that the object is passed to. So, in theory, even a
logging function cannot use the object. Hm...
The question of constness of invariant/contracts has been raised,
I do think the object should be const, but Andrei think otherwise.