How to prove static invariant (of an enum) in different heap? #3697
Answered
by
WolframPfeifer
FliegendeWurst
asked this question in
Q&A
-
|
I have an enum So I end up with a sequent like: But I can't make use of the formula on the right. There is also no option to use a dependency contract. |
Beta Was this translation helpful? Give feedback.
Answered by
WolframPfeifer
Dec 12, 2025
Replies: 1 comment 1 reply
-
|
Here is a full example: enum JMERuleErrorType {
INFO,
WARNING,
CRITICAL;
}
class Usecase {
/*@ public normal_behavior
@ requires \static_invariant_for(JMERuleErrorType);
@ ensures \result != null;
@*/
public JMERuleErrorType produceEnum() {
return JMERuleErrorType.INFO;
}
/*@ public normal_behavior
@ requires \static_invariant_for(JMERuleErrorType);
@ ensures \result != null;
@*/
public JMERuleErrorType callMethodTwice() {
produceEnum();
return produceEnum();
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this concrete case, you could add a postcondition
ensures \static_invariant_for(JMERuleErrorType)to produceEnum. However, this is not a general solution. I think, most of the time, it should be possible to add\static_invariant_for(JMERuleErrorType)to the non-static invariant (of the class UseCase in this example). Since in the enum everything is final, I think this could be sufficient. For static invariants in general, I am not sure if this is enough. Unfortunately, as far as I know it is not possible to define dependency contracts for static invariants. I was thinking about something likeaccessible \static_inv: <locset_term>, however, it is not supported.