typetools / typetools/checker-framework
Feature request: WPI should infer conditional postconditions
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Given the following Java class:
import java.util.Optional;
import org.checkerframework.checker.optional.qual.Present;
import org.checkerframework.framework.qual.EnsuresQualifierIf;
import org.checkerframework.dataflow.qual.Pure;
public class Main {
public static void main(String[] args) {
OptStringContainer optStrCont = new OptStringContainer("Hello");
if (optStrCont.isStringEqTo("Hello")) {
System.out.println(optStrCont.getOptStr().get());
}
}
private static class OptStringContainer {
public String str;
public OptStringContainer(String str) {
this.str = str;
}
public Optional<String> getOptStr() {
return Optional.of(str);
}
public boolean isStringEqTo(String other) {
return getOptStr().isPresent() && getOptStr().get().equals(other);
}
}
}
WPI should be able to infer flow-sensitive type refinement annotations. Specifically, WPI should be able to infer the following annotation for OptStringContainer#isStringEqTo:
@EnsuresQualifierIf(result = true, expression = "getOptStr()", qualifier = Present.class)
public boolean isStringEqTo(String other) {
return getOptStr().isPresent() && getOptStr().get().equals(other);
}
Given that @Pure is inferred for OptStringContainer#getOptStr
After WPI is able to infer these annotations, running the Optional Checker on the annotated code should output no errors.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with WPI's handling of conditional postconditions and inferred @Pure annotations, using the provided OptStringContainer example as the entry point. Check how the Optional Checker consumes the inferred @EnsuresQualifierIf annotation; done means the annotation is inferred for isStringEqTo and the annotated code produces no Optional Checker errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100