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

Addition with LessThan #229

Open
kelloggm opened this issue May 30, 2018 · 3 comments
Open

Addition with LessThan #229

kelloggm opened this issue May 30, 2018 · 3 comments

Comments

@kelloggm
Copy link
Owner

kelloggm commented May 30, 2018

Given a, b, and c are all non-negative integers, and b < c, then we can conclude that a + b < a + c.

Consider the following example from Guava:

    public List<Short> subList(
            @IndexOrHigh("this") @LessThan("#2") int fromIndex,
            @IndexOrHigh("this") int toIndex) {
      int size = size();
      checkPositionIndexes(fromIndex, toIndex, size);
      if (fromIndex == toIndex) {
        return Collections.emptyList();
      }
      return new ShortArrayAsList(array, start + fromIndex, start + toIndex);
    }

The constructor call on the last line requires the second parameter to be less than the third.

@smillst
Copy link
Collaborator

smillst commented May 30, 2018

I don't think it matters if a, b, or c are non-negative. If b < c then a + b < a + c.

@mernst
Copy link
Collaborator

mernst commented May 30, 2018

Modulo overflow, of course.

@kelloggm
Copy link
Owner Author

You're both right. I think it's worth implementing anyway - the Index Checker is already unsound wrt overflow.

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

3 participants