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.