Invariants - Stack overflow
If I declare an invariant which relies on methods which have contracts leads to: SystemStackError: stack level too deep.
Currently all invariants get validated after each contracted method call here: https://github.com/egonSchiele/contracts.ruby/blob/master/lib/contracts/call_with.rb#L87
So that is only logical that it fails with stack level too deep if invariant itself calls any contracted method.
It sounds like the proper course of action is to keep a state about the fact, if invariants gets validated currently or not. And verify_contracts! will do nothing if current state says that they are already verified at the moment.
Other course of action is to re-think invariants concept. For example when they exactly should get checked? Before method calls? After method calls? Both?
And by the way I just remembered, invariants logic should be factored out to Engine module. Because currently core contracts add only 2 methods to classes, ie: Contract and __contracts_ruby (which contains engine object inside). But invariants just add Invariant and verify_invariants! method, which makes it source of possible conflict with some user code, it would be good to move verify_invariants! to engine too. Currently engine is stored only in class and eigenclass, but invariants with such state will have to store their state per instance and it means that instances should contain contracts engine too - or its slim version: invariants engine.
WDYT?