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

Signedness Checker emits false positive when a char is assigned to an int or long and returned #3710

Closed
DmitriyShepelev opened this issue Sep 29, 2020 · 0 comments · Fixed by #3726

Comments

@DmitriyShepelev
Copy link
Contributor

The Signedness Checker emits a false positive when a char is assigned to an int or a long and returned:

public class RemainingUnsignedness {
    int returnIntWithLocalVariable(char c) {
        int i = c;
        return i;
    }

    long returnLongWithLocalVariable(char c) {
        long l = c;
        return l;
    }

    int returnIntWithoutLocalVariable(char c) {
        return c;
    }

    long returnLongWithoutLocalVariable(char c) {
        return c;
    }
}

Output:

root@DESKTOP-MO4BCEL:~/checker-framework# javacheck -processor SignednessChecker ~/temp-checker/checker-framework/checker/tests/signedness/RemainingUnsignedness.java
/root/temp-checker/checker-framework/checker/tests/signedness/RemainingUnsignedness.java:4: error: [return.type.incompatible] incompatible types in return.
        return i;
               ^
  type of expression: @Unsigned int
  method return type: @Signed int
/root/temp-checker/checker-framework/checker/tests/signedness/RemainingUnsignedness.java:9: error: [return.type.incompatible] incompatible types in return.
        return l;
               ^
  type of expression: @Unsigned long
  method return type: @Signed long
2 errors

javacheck alias:
alias javacheck='$CHECKERFRAMEWORK/checker/bin/javac'

The methods returnIntWithoutLocalVariable and returnLongWithoutLocalVariable not emitting this false positive demonstrates the necessity of a local variable in emitting this false positive.

mernst added a commit to mernst/checker-framework that referenced this issue Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant