Navigation Menu

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

Postcondition annotations that reference "this" in conditional blocks aren't lubbed correctly afterward #4806

Closed
kelloggm opened this issue Jul 16, 2021 · 0 comments · Fixed by #4807

Comments

@kelloggm
Copy link
Contributor

Consider the following program (checked in as checker/tests/calledmethods/EnsuresCalledMethodsThisLub.java on this branch: https://github.com/kelloggm/checker-framework/tree/postcondition-this-bug):

import org.checkerframework.checker.calledmethods.qual.CalledMethods;
import org.checkerframework.checker.calledmethods.qual.EnsuresCalledMethods;

class EnsuresCalledMethodsThisLub {

  @EnsuresCalledMethods(
      value = "#1",
      methods = {"toString", "equals"})
  void call1(Object obj) {
    obj.toString();
    obj.equals(null);
  }

  @EnsuresCalledMethods(
      value = "#1",
      methods = {"toString", "hashCode"})
  void call2(Object obj) {
    obj.toString();
    obj.hashCode();
  }

  void test(boolean b) {
    if (b) {
      call1(this);
    } else {
      call2(this);
    }
    @CalledMethods("toString") Object obj1 = this;
    // :: error: (assignment)
    @CalledMethods({"toString", "equals"}) Object obj2 = this;
  }

  void test_arg(Object arg, boolean b) {
    if (b) {
      call1(arg);
    } else {
      call2(arg);
    }
    @CalledMethods("toString") Object obj1 = arg;
    // :: error: (assignment)
    @CalledMethods({"toString", "equals"}) Object obj2 = arg;
  }
}

I expect that the two errors above will be issued. However, when this test is run, only the second error is issued.

In particular, the type of this in test after the end of the if statement is @CalledMethods({"toString", "equals", "call1"}) - indicating that only the then store was propagated past the end of the if block. Instead, I would expect the two stores to be LUB'd to give @CalledMethods("toString"), as occurs in the second example (test_arg()).

I don't know of any of other type system that has a postcondition annotation that can reference this besides Called Methods, so I haven't reproduced this with any other checker. However, this issue came up when trying to add postcondition inference for "this" to WPI, so I've observed it with the AinferTestChecker and I believe it would apply to any checker where postcondition annotations whose expression resolves to this makes sense.

@mernst mernst linked a pull request Jul 16, 2021 that will close this issue
mernst added a commit that referenced this issue Jul 16, 2021
Co-authored-by: Martin Kellogg <kelloggm@cs.washington.edu>
wmdietl pushed a commit to eisop/checker-framework that referenced this issue Aug 3, 2021
Co-authored-by: Martin Kellogg <kelloggm@cs.washington.edu>
wmdietl pushed a commit to eisop/checker-framework that referenced this issue Aug 3, 2021
Co-authored-by: Martin Kellogg <kelloggm@cs.washington.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants