You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Subtracting @IndexOrHigh("a") from a.length yields @NonNegative, and subtracting @IndexFor("a") from a.length yields @Positive.
However, since the Upper Bound Checker is dependent on the Lower Bound Checker, the Lower Bound Checker probably cannot make these inferences.
These inferences would help in situations when we specify a range at the end of an array (referring to a suffix of the array).
importorg.checkerframework.checker.index.qual.IndexFor;
importorg.checkerframework.checker.index.qual.IndexOrHigh;
importorg.checkerframework.checker.index.qual.NonNegative;
publicclassSubtractFromLength {
publicvoidm(Object[] a, @IndexOrHigh("#1") inti) {
@NonNegativeintj = a.length - i; // line 7
}
// Example adapted from Guava UnsignedLongs.toStringpublicStringarraySuffixToString(char[] a, @IndexFor("#1") inti) {
returnnewString(a, i, a.length-i); // line 12
}
}
Output:
SubtractFromLength.java:7: error: [assignment.type.incompatible] incompatible types in assignment.
@NonNegative int j = a.length - i;
^
found : @LowerBoundUnknown int
required: @NonNegative int
SubtractFromLength.java:12: error: [argument.type.incompatible] incompatible types in argument.
return new String(a, i, a.length-i);
^
found : @LowerBoundUnknown int
required: @NonNegative int
2 errors
Expected: no warnings.
The text was updated successfully, but these errors were encountered:
Subtracting
@IndexOrHigh("a")
froma.length
yields@NonNegative
, and subtracting@IndexFor("a")
froma.length
yields@Positive
.However, since the Upper Bound Checker is dependent on the Lower Bound Checker, the Lower Bound Checker probably cannot make these inferences.
These inferences would help in situations when we specify a range at the end of an array (referring to a suffix of the array).
Possibly related: #96
Code:
Output:
Expected: no warnings.
The text was updated successfully, but these errors were encountered: