Output contract's arguements

Peter Alexander peter.alexander.au at gmail.com
Thu Sep 19 10:53:02 PDT 2013


On Thursday, 19 September 2013 at 17:25:37 UTC, Andrei 
Alexandrescu wrote:
> 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.

Is this by design? That seems inconsistent to me, but maybe I'm 
missing something.

This passes btw:

struct S
{
     int y;
}

interface A
{
     void fun(S x) out { assert(x.y == 42); }
}

class B : A
{
     void fun(S x) { x.y = 42; }
}

void main()
{
     A a = new B;
     a.fun(S(0));
}

So, sometimes it uses the old value and sometimes it uses the new 
value?


More information about the Digitalmars-d mailing list