Skip to content
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

Feature request: WPI should infer conditional postconditions #6237

Open
jyoo980 opened this issue Oct 13, 2023 · 0 comments
Open

Feature request: WPI should infer conditional postconditions #6237

jyoo980 opened this issue Oct 13, 2023 · 0 comments

Comments

@jyoo980
Copy link
Contributor

jyoo980 commented Oct 13, 2023

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.

@mernst mernst changed the title Feature request: WPI should infer flow-sensitive type refinement annotations Feature request: WPI should infer conditional postconditions Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants