typetools / typetools/checker-framework
After `s.contains(b)` returns true, `s.indexOf()` should have an `@IntRange` type
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Consider the following code-
Command-
javac -processor signedness issue.java
Input-
import org.checkerframework.common.value.qual.*;
class issue {
static final String s = "abcdefghijklmnopqrstuvwxyz";
static void m1(String b) {
if (s.contains(b)) {
@IntRange(from=0, to=25) int temp = s.indexOf(b);
}
}
}
Output-
ex.java:6: error: [assignment.type.incompatible] incompatible types in assignment.
@IntRange(from=0, to=25) int temp = s.indexOf(b);
^
found : @UnknownVal int
required: @IntRange(from=0, to=25) int
1 error
The error should not occur because if String s will contain String b then temp cannot be negative, therefore IntRange should satisfy this condition. I think the problem is that it is unable to detect the range of indexOf() otherwise this error would not occur.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided issue.java example and run javac -processor signedness issue.java to reproduce the assignment error. Trace the signedness checker's handling of String.contains and String.indexOf, then add coverage showing that a successful contains check permits the nonnegative @IntRange assignment without an incompatible-type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100