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

Local variable gets incorrectly unrefined in finally block #3484

Closed
t-rasmud opened this issue Jul 20, 2020 · 0 comments · Fixed by #3550
Closed

Local variable gets incorrectly unrefined in finally block #3484

t-rasmud opened this issue Jul 20, 2020 · 0 comments · Fixed by #3550
Assignees

Comments

@t-rasmud
Copy link
Contributor

t-rasmud commented Jul 20, 2020

Consider a type system with the qualifier hierarchy @DefaultType <: @TopType where @DefaultType is the default qualifier in hierarchy (find source here).
Consider the following test case in this type system:

import org.checkerframework.checker.casting.qual.DefaultType;

@SuppressWarnings({"exception.parameter.invalid", "inconsistent.constructor.type"}) // for implicit constructor
public class TestCasts {
    void repro(@DefaultType long startTime) {
        try {
            System.out.println("Inside try");
            return;
        } catch (Exception ex) {
            long timeTaken = startTime;
            @DefaultType double dblTimeTaken = timeTaken;

            throw new IllegalArgumentException(ex);
        } finally {
            long timeTaken = startTime;
            @DefaultType double dblTimeTaken = timeTaken;
        }
    }
}

The same code appears in the catch and finally blocks.

Running the casting checker on the test case using the command javac -processor casting checker/tests/casting/TestCasts.java results in the following unexpected error for the finally block (but not for the catch block):

checker/tests/casting/TestCasts.java:15: error: [assignment.type.incompatible] incompatible types in assignment.
            @DefaultType double dblTimeTaken = timeTaken;
                                               ^
  found   : @TopType long
  required: @DefaultType double
1 error

It looks like perhaps the local variable timeTaken is incorrectly unrefined to @TopType in the finally block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants