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

Casting Char to Int fail signedness checker #5256

Closed
yongweiy opened this issue Aug 13, 2022 · 2 comments
Closed

Casting Char to Int fail signedness checker #5256

yongweiy opened this issue Aug 13, 2022 · 2 comments

Comments

@yongweiy
Copy link

final class C {
  char c;
  public int foo() {
    int x = 1;
    x = x + (int) c;
    return x;
  }
}

gives

error: [return.type.incompatible] incompatible types in return.
    return x;
           ^
  type of expression: @Unsigned int
  method return type: @Signed int

However, this is okay.

final class C {
  public int foo() {
    char c = 65535;
    int x = 1;
    x = x + (int) c;
    return x;
  }
}

I wonder if it is a false positive.

My current workaround is to trade the error for a warning.

import org.checkerframework.checker.signedness.qual.SignedPositive;

final class C {
  char c;
  public int foo() {
    int x = 1;
    x = x + (@SignedPositive int) c;
    return x;
  }
}

results in

warning: [cast.unsafe] cast from "@Unsigned char" to "@SignednessGlb int" cannot be statically verified
    x = x + (@SignedPositive int) c;
            ^
mernst added a commit to mernst/checker-framework that referenced this issue Aug 13, 2022
mernst added a commit that referenced this issue Aug 13, 2022
@mernst
Copy link
Member

mernst commented Aug 13, 2022

Thanks for your bug report. I'm sorry you are having trouble.

What version of the Checker Framework are you using?
I was unable to reproduce your problem on the latest version of the Checker Framework from its version control repository. You can see that #5257 is passing tests.

@yongweiy
Copy link
Author

Thanks for looking into it, Michael!

You are right. I am using an old version (3.6.0) of the Checker Framework.

Sorry about the confusion. I will close the issue.

wmdietl pushed a commit to eisop/checker-framework that referenced this issue Sep 2, 2022
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

2 participants