File: RefineNeqLength.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (81 lines) | stat: -rw-r--r-- 2,893 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Test case for Issue panacekcz#12:
// https://github.com/panacekcz/checker-framework/issues/12

import org.checkerframework.checker.index.qual.IndexFor;
import org.checkerframework.checker.index.qual.IndexOrHigh;
import org.checkerframework.checker.index.qual.LTLengthOf;
import org.checkerframework.checker.index.qual.LTOMLengthOf;
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.common.value.qual.IntVal;

class RefineNeqLength {
    void refineNeqLength(int[] array, @IndexOrHigh("#1") int i) {
        // Refines i <= array.length to i < array.length
        if (i != array.length) {
            refineNeqLengthMOne(array, i);
        }
        // No refinement
        if (i != array.length - 1) {
            // :: error: (argument.type.incompatible)
            refineNeqLengthMOne(array, i);
        }
    }

    void refineNeqLengthMOne(int[] array, @IndexFor("#1") int i) {
        // Refines i < array.length to i < array.length - 1
        if (i != array.length - 1) {
            refineNeqLengthMTwo(array, i);
            // :: error: (argument.type.incompatible)
            refineNeqLengthMThree(array, i);
        }
    }

    void refineNeqLengthMTwo(int[] array, @NonNegative @LTOMLengthOf("#1") int i) {
        // Refines i < array.length - 1 to i < array.length - 2
        if (i != array.length - 2) {
            refineNeqLengthMThree(array, i);
        }
        // No refinement
        if (i != array.length - 1) {
            // :: error: (argument.type.incompatible)
            refineNeqLengthMThree(array, i);
        }
    }

    void refineNeqLengthMTwoNonLiteral(
            int[] array,
            @NonNegative @LTOMLengthOf("#1") int i,
            @IntVal(3) int c3,
            @IntVal({2, 3}) int c23) {
        // Refines i < array.length - 1 to i < array.length - 2
        if (i != array.length - (5 - c3)) {
            refineNeqLengthMThree(array, i);
        }
        // No refinement
        if (i != array.length - c23) {
            // :: error: (argument.type.incompatible)
            refineNeqLengthMThree(array, i);
        }
    }

    @LTLengthOf(value = "#1", offset = "3") int refineNeqLengthMThree(
            int[] array, @NonNegative @LTLengthOf(value = "#1", offset = "2") int i) {
        // Refines i < array.length - 2 to i < array.length - 3
        if (i != array.length - 3) {
            return i;
        }
        // :: error: (return.type.incompatible)
        return i;
    }

    // The same test for a string.
    @LTLengthOf(value = "#1", offset = "3") int refineNeqLengthMThree(
            String str, @NonNegative @LTLengthOf(value = "#1", offset = "2") int i) {
        // Refines i < str.length() - 2 to i < str.length() - 3
        if (i != str.length() - 3) {
            return i;
        }
        // :: error: (return.type.incompatible)
        return i;
    }
}