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

Inference of IndexOrHigh after a for loop #221

Open
panacekcz opened this issue Apr 4, 2018 · 0 comments
Open

Inference of IndexOrHigh after a for loop #221

panacekcz opened this issue Apr 4, 2018 · 0 comments

Comments

@panacekcz
Copy link

The index checker does not infer the @IndexOrHigh qualifier for a variable that has been used as an index to iterate over an array in a for loop. After the loop, the variable contains the length of an array (if the loop is exitted normally) or an index for the array (if the loop is exitted by break). Therefore, it can be safely considered to be @IndexOrHigh for the array.

Encountered in Guava.

Could it be a limitation of the dataflow implementation?

Code:

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

public class IndexOrHighInfer {
	void m(Object[] a) {
	    int i;
	    for (i = 0; i < a.length; i++) {
	      if(a[i] == null)
	    	  break;
	    }
	    
	    @IndexOrHigh("a") int j = i;
	}
}

Output:

IndexOrHighInfer.java:11: error: [assignment.type.incompatible] incompatible types in assignment.
	    @IndexOrHigh("a") int j = i;
	                              ^
  found   : @UpperBoundUnknown int
  required: @LTEqLengthOf("a") int
1 error

Expected: no warning.

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

1 participant