panacekcz / checker-framework

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

Math.max should preserve IndexFor #20

Closed panacekcz closed 6 years ago

panacekcz commented 7 years ago

When two indices are merged using Math.max, the result is also an index.

void m(int[] a, @IndexFor("#1") int i1, @IndexFor("#1") int i2){
 int v = a[Math.max(i1,i2)];
}

Will a polymorphic qualifier work?

panacekcz commented 7 years ago

A solution based on polymorphic qualifier or special handling in the checker should be easy. Might also apply to Math.min and others.

panacekcz commented 7 years ago

Math.min already has a special support. https://github.com/typetools/checker-framework/blob/951cb42b38faac05d9419ade07be87893643dd5c/checker/src/org/checkerframework/checker/index/upperbound/UpperBoundAnnotatedTypeFactory.java#L411

panacekcz commented 6 years ago

Fixed by typetools#1472.