Question about contracts on methods.

Peter C. Chapin pcc482719 at gmail.com
Sat Nov 28 18:14:14 PST 2009


Lutger <lutger.blijdestijn at gmail.com> wrote in
news:hescc2$161$1 at digitalmars.com: 

> You are not missing something, this is a known issue. It has been
> discussed and I believe the intention was to do something about this,
> but with all the high priorities I'm not sure when this will be
> solved. 

Okay, thanks for the information. It occurs to me that one way to solve 
this problem would be to allow declarations in the precondition be 
visible in the post condition. Then one could do something like

    void next()
    in {
        int original_day_m   = day_m;
        int original_month_m = month_m;
        int original_year_m  = year_m;
    }
    out {
        assert( ... expression using original_day_m, etc ... )
    }
    body {
      // No code related to pre or post conditions.
    }

This might not be an ideal resolution but it seems a lot better than the 
current situation and it doesn't look like it would be too hard to 
implement (but what do I know!).


> As for the code that should not be compiled: this is easy to solve...

Thanks for your suggestions!

Peter


More information about the Digitalmars-d-learn mailing list