Open kelloggm opened 7 years ago
I originally thought this was an Index Checker problem; kelloggm#127 has some examples of the problem's manifestations in the Index Checker.
Here are some similar Index Checker test cases:
import org.checkerframework.checker.index.qual.IndexFor;
import org.checkerframework.checker.index.qual.NonNegative;
public class ArrayAssignmentSameLenTest {
static class Partial {
private final int[] iValues;
Partial(@NonNegative int n) {
iValues = new int[n];
}
}
private final Partial iBase;
private final @IndexFor("iBase.iValues") int iFieldIndex;
ArrayAssignmentSameLenTest(Partial partial, @IndexFor("#1.iValues") int fieldIndex) {
iBase = partial;
iFieldIndex = fieldIndex;
}
}
import org.checkerframework.checker.index.qual.*;
class ObjectAssignment {
int x;
static void do_things(ObjectAssignment a, ObjectAssignment b) {
a.x = 5; // a.x is @Positive
b = a; // b.x is now a.x, so it's also @Positive
@Positive int y = b.x; // issues a warning
@Positive int z = a.x; // does not issue a warning
}
}
Consider the following example from the nullness checker:
This also occurs in other checkers (e.g. Index). In general, if an object
a
with fieldf
is assigned (i.e.a = b
), thena.f
should have the same type asb.f
.