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

Value Checker issue with boxed primitives and type refinements #687

Open
wmdietl opened this issue Jan 29, 2024 · 0 comments
Open

Value Checker issue with boxed primitives and type refinements #687

wmdietl opened this issue Jan 29, 2024 · 0 comments

Comments

@wmdietl
Copy link
Member

wmdietl commented Jan 29, 2024

When a boxed primitive is refined, that refinement is only stored with the un-boxed value, not with the original boxed primitive:

> cat Demo.java 
class Demo {
  void foo(Integer i) {
    int x = i > 5 ? i : 5;
  }
}

> ./checker/bin/javac -processor value Demo.java
Demo.java:3: error: [conditional.type.incompatible] incompatible types in conditional expression.
    int x = i > 5 ? i : 5;
                    ^
  found   : Integer
  required: @IntRange(from=5, to=2147483647) int
1 error
> cat Demo.java
import org.checkerframework.common.value.qual.IntVal;

class Demo {
  @IntVal(5) int foo(Integer i) {
    if (i == 5) {
       return i;
    } else {
      return 5;
    }
  }
}
wdietl@beryl ~/w/e/checker-framework-hacking (master)> ./checker/bin/javac -processor value Demo.java
Demo.java:6: error: [return.type.incompatible] incompatible types in return.
       return i;
              ^
  type of expression: Integer
  method return type: @IntVal(5L) int
1 error

Both examples pass if the parameter i is changed to int.

Thanks @thomaskirz for the report!

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

No branches or pull requests

1 participant