typetools / typetools/checker-framework
IndexChecker false warning in length - index situations
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
Consider the snippet:
import org.checkerframework.checker.index.qual.IndexOrHigh;
import org.checkerframework.checker.index.qual.NonNegative;
public class Testing {
public @NonNegative int method(int[] array, @IndexOrHigh("#1") int var) {
return array.length - var;
}
}
Running javac -processor org.checkerframework.checker.index Testing.java, you will get the following error:
Error:(6, 29) java: [return.type.incompatible] incompatible types in return.
type of expression: @LowerBoundUnknown int
method return type: @NonNegative int
If var is a valid index for array, or equal to array.length, then the value returned is always 0 or greater.
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
Reproduce the warning with the Testing.java snippet and the javac command using the org.checkerframework.checker.index processor. Start by tracing the IndexChecker handling of @IndexOrHigh values in the length - index expression. Done means the shown method type-checks without the incompatible-return warning while preserving the expected non-negative result.
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
- 45/100