panacekcz / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
0 stars 0 forks source link

-1 is always a valid SubstringIndexFor #24

Closed panacekcz closed 6 years ago

panacekcz commented 6 years ago

Code:

import org.checkerframework.checker.index.qual.SubstringIndexFor;

public class ReturnSubstringIndex {
    public @SubstringIndexFor(value="#1", offset="#2.length()-1") int indexOf(String a, String b) {
        return -1;
    }
}

Output:

ReturnSubstringIndex.java:5: error: [return.type.incompatible] incompatible types in return.
        return -1;
               ^
  found   : @SubstringIndexUnknown int
  required: @SubstringIndexFor(value="a", offset="b.length() - 1") int
1 error

Expected: no warning.

panacekcz commented 6 years ago

Replaced by kelloggm#206.