-
Notifications
You must be signed in to change notification settings - Fork 41
fixes #3670: KeY does not know that enum constants are non-null #3676
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
base: main
Are you sure you want to change the base?
Conversation
|
I tested it on this code. The methods can be verified. Alas, public enum Severity {
INFO,
WARNING,
CRITIQUE
}
public class Checker {
/*@ public normal_behaviour
@ ensures \result != null;
@*/
Severity checkIt() {
return Severity.INFO;
}
/*@ public normal_behaviour
@ ensures \result == 1;
@*/
int ord() {
return Severity.WARNING.ordinal();
}
/*@ public normal_behaviour
@ ensures \result != Severity.CRITIQUE;
@*/
Severity different() {
return Severity.INFO;
}
} |
|
Please check for logical soundness. It felt correct, but I have not really checked. |
wadoon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I would tell is that the support is incomplete:
- Is
e <: java.lang.Enumvalid for all enums instancese? - Some methods are missing of
java.lang.Enum - The static generated
E.values()method is missing.
Do you think, we should rather downcompile to Java with final fields?
| * in a lookup map from name to (ordinal index, program variable) | ||
| */ | ||
| private final List<IProgramVariable> constants = new ArrayList<>(); | ||
| private final Map<String, Pair<@NonNull Integer, @NonNull IProgramVariable>> constants = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that this class is inside the immutable KeY Java AST.
Can we avoid a mutable data structure here?
I would say that an ImmutableList<IProgramVariables> should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An immutable map would work. It has been a mutable DS before.
key.core/src/main/java/de/uka/ilkd/key/nparser/varexp/TacletBuilderManipulators.java
Show resolved
Hide resolved
|
This breaks if the enum constructor throws an exception.
|
|
In which sense, does this break for errors during initialization? The JLS gives no direct answer. The nearest case would be "Example 8.9.2-1. Restriction On Enum Constant Self-Reference". |
Related Issue
This pull request resolves #3670.
Intended Change
Enum constants are finally supported again (after initial support between 2006 and 2011).
Features
.ordinal()can be retrieved.Type of pull request
Ensuring quality
I would like to leave this to @FliegendeWurst and @WolframPfeifer who need this feature in a case study and can study this there, find bugs and add test cases from the study.
Additional information and contact(s)
Case study by @FliegendeWurst, @WolframPfeifer
The contributions within this pull request are licensed under GPLv2 (only) for inclusion in KeY.