-
Notifications
You must be signed in to change notification settings - Fork 67
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
Contract: Add invariant
contract
#2829
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Delja
force-pushed
the
contract_refactoring
branch
from
July 14, 2020 19:51
0b25d77
to
27948de
Compare
Delja
force-pushed
the
contract_refactoring
branch
from
August 20, 2020 20:55
36113e8
to
fb61a9c
Compare
Signed-off-by: Florian Deljarry <[email protected]>
Improve comment to be more explicit of the purpose of `mcontract_facet` Signed-off-by: Florian Deljarry <[email protected]>
Signed-off-by: Florian Deljarry <[email protected]>
Signed-off-by: Florian Deljarry <[email protected]>
Move the contract options in the appropriate module contract Signed-off-by: Florian Deljarry <[email protected]>
Signed-off-by: Florian Deljarry <[email protected]>
Signed-off-by: Florian Deljarry <[email protected]>
Update man page to add `--in-out-invariant` option Signed-off-by: Florian Deljarry <[email protected]>
Signed-off-by: Florian Deljarry <[email protected]>
Delja
force-pushed
the
contract_refactoring
branch
from
September 3, 2020 21:47
fb61a9c
to
dbe708a
Compare
Test Results 67 files 338 suites 17m 33s ⏱️ Results for commit dbe708a. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pr adds invariant feature.
Annotations
To define a new class contract you need to use the
invariant
annotation. The principle is the same as the other contractexpect
andensure
all expressions returning a boolean (comparison, method call ...) can be used as a condition.Invariant generation process
When a contract is detected, the code is extended to add verification functionality. A new method is then introduced to verify the invariant clause.
When a class has an invariant contract, all methods (redef, inherited, intro) have now two contracts facet to check it. One for the invariant verification and one for a potential ensures, expect or both verification. This split was made to avoid the invariant verification on self.
Note: All properties defined in
object
are considered as pure and therefore they don't have an invariant facet. This offers two advantages, we avoid an overcost on all the classes that will useobject
properties, as well as a problematic for checking null type (==
and!=
).Representation of the compiled class
The invariant method was added on the object class to resolve multi inheritance problem with a systematic call to
super
.Option
Invariant contracts are normally supposed to be checked in enter and exit. But in Nit the verification is only made at the exit of the method. It is however possible to activate the checking of the input and output invariants with the
--in-out-invariant
option.Refactoring
Now the contract
toolcontext
options are defined in the contract module. It's seems to be a better place to keep the options and the implementation in the same module.