DIP 1009--Improve Contract Usability--Preliminary Review Round 1

Mark via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 27 15:45:17 PDT 2017


On Tuesday, 20 June 2017 at 11:57:55 UTC, Mike Parker wrote:
> DIP 1009 is titled "Improve Contract Usability".
>
> [...]

Veering a bit off topic,the compiler doesn't treat contracts any 
different from other code, does it? For instance, consider:

int foo()
out(result; result>0)
{
// whatever
}

int bar(int x)
in (x<0)
{
// whatever
}

int main() {
     return bar(foo());
}

I would have liked to get a *compile-time* error in case of such 
a trivial contract violation. Of course, I don't expect the 
compilier to try and prove that a contract holds (seems 
unrealitic and not so useful) but it would be nice if it could at 
least spot simple errors, like in the example above.

In a similar vein, the information conveyed in a contract can 
potentially be used to apply simple optimizations, at least in 
trivial cases.

If the contract system amounts to placing assertions at the 
beginning and/or end of a function, it doesn't seem so useful 
except for documentation and readability.


More information about the Digitalmars-d mailing list