Suggested Change to Contract Syntax

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 10 14:39:54 PST 2016


On Thursday, 10 March 2016 at 22:04:24 UTC, Xinok wrote:
> I'm not sure how the compilers translate the contracts into 
> code, but it's definitely feasible. Code of the form:
>
>     auto foo()
>     in{ ... }
>     out(result){ ... }
>     body{ ... }
>
> Could simply be rewritten as:



Not quite because contracts are inherited. For a child class, 
either the child OR the parent's in contract needs to pass, but 
both the child AND parent's out contracts need to pass.

The result is that the child in contract might run without the 
parent in... but then the parent's out will still be run.

Will it see uninitialized variables? Or partially run stuff as 
the in contract throws a swallowed exception half way through?


Contracts are most interesting in the case of inheritance and 
keeping variables between them isn't going to be easy.


More information about the Digitalmars-d mailing list