Out contracts: how to refer to objects' start state

Peter Williams pwil3058 at bigpond.net.au
Sat May 25 19:02:41 PDT 2013


On 26/05/13 11:47, Andrei Alexandrescu wrote:
> On 5/25/13 9:18 PM, Adam D. Ruppe wrote:
>> On Sunday, 26 May 2013 at 01:12:35 UTC, Andrei Alexandrescu wrote:
>>> On 5/25/13 9:03 PM, Andrej Mitrovic wrote:
>>>> On 5/26/13, Andrei Alexandrescu<SeeWebsiteForEmail at erdani.org>
>>>>> in { auto oldLen = this.length; }
>>>> out { assert(this.length == in.oldLen + 1); }
>>
>>> Since every in.xyz expression could access an arbitrary method of the
>>> old object,
>>
>> Here, in.oldLen refers to the local variable you defined in the in{}
>> scope, as opposed to plain oldLen which would be searing the out{} scope.
>
> Ohh, I see. Yes, that could work.

That revelation also answers my question about how it could break code.

Peter



More information about the Digitalmars-d mailing list