-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pre- and Post- conditions management in functions: a syntax proposal #9
Comments
If the proposed syntax is allowed to return a value from a function, the compiler must avoid local definition of variables of the same name. |
The work on this issue should be done at the same time as the one for the issue #55. |
We may introduce invariant conditions also:
|
Currently, the
Currently, the generic type definitions could be assimilated to invariants. |
Considering the precondition example given by @ngaud. It could be written with the current SARL syntax:
Of course, the SARL compiler must be updated for detecting public String push(final String s, final Integer i) {
assert !Strings.isEmpty(s) : "Invalid pre-condition \"!Strings::isEmpty(s)\"'";
assert i > 0 : "Invalid pre-condition \"i>0\"'";
// The code
return null;
} Regarding the postcondition, we may define a keyword "post ".
The public String push(final String s, final Integer i) {
String $$returnedValue;
try {
// The code
$$returnedValue = null;
return $$returnedValue;
} finally {
final String it = $$returnedValue;
assert Strings::isEmpty(it) : "Invalid postcondition \"Strings::isEmpty(it)\"";
}
} |
Pre and post conditions should also be used for static validation by the SARL compiler. |
This issue in now part of the PhD thesis of @tpiotrow. |
This is a proposal for the syntax related to functions definition and their associated pre- and post- conditions
The text was updated successfully, but these errors were encountered: