| 1 |
// Test case for Issue 548: |
| 2 |
// https://github.com/typetools/checker-framework/issues/548 |
| 3 |
|
| 4 |
class TryFinallyContinue { |
| 5 |
String testWhile1() { |
| 6 |
String ans = "x"; |
| 7 |
while (true) { |
| 8 |
if (true) { |
| 9 |
// :: error: (return.type.incompatible) |
| 10 |
return ans; |
| 11 |
} |
| 12 |
if (true) { |
| 13 |
try { |
| 14 |
continue; |
| 15 |
} finally { |
| 16 |
ans = null; |
| 17 |
} |
| 18 |
} |
| 19 |
ans = "x"; |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
String testWhile2(boolean cond) { |
| 24 |
String ans = "x"; |
| 25 |
while (cond) { |
| 26 |
if (true) { |
| 27 |
return ans; |
| 28 |
} |
| 29 |
try { |
| 30 |
ans = null; |
| 31 |
continue; |
| 32 |
} finally { |
| 33 |
ans = "x"; |
| 34 |
} |
| 35 |
} |
| 36 |
return ans; |
| 37 |
} |
| 38 |
|
| 39 |
String testWhile3(boolean cond) { |
| 40 |
String ans = "x"; |
| 41 |
OUTER: |
| 42 |
while (true) { |
| 43 |
if (true) { |
| 44 |
// :: error: (return.type.incompatible) |
| 45 |
return ans; |
| 46 |
} |
| 47 |
|
| 48 |
try { |
| 49 |
while (cond) { |
| 50 |
if (true) { |
| 51 |
try { |
| 52 |
continue OUTER; |
| 53 |
} finally { |
| 54 |
ans = "x"; |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
} finally { |
| 59 |
ans = null; |
| 60 |
} |
| 61 |
ans = "x"; |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
String testFor1() { |
| 66 |
String ans = "x"; |
| 67 |
for (; ; ) { |
| 68 |
if (true) { |
| 69 |
// :: error: (return.type.incompatible) |
| 70 |
return ans; |
| 71 |
} |
| 72 |
if (true) { |
| 73 |
try { |
| 74 |
continue; |
| 75 |
} finally { |
| 76 |
ans = null; |
| 77 |
} |
| 78 |
} |
| 79 |
ans = "x"; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
String testFor2(boolean cond) { |
| 84 |
String ans = "x"; |
| 85 |
for (; cond; ) { |
| 86 |
if (true) { |
| 87 |
return ans; |
| 88 |
} |
| 89 |
try { |
| 90 |
ans = null; |
| 91 |
continue; |
| 92 |
} finally { |
| 93 |
ans = "x"; |
| 94 |
} |
| 95 |
} |
| 96 |
return ans; |
| 97 |
} |
| 98 |
|
| 99 |
String testFor3(boolean cond) { |
| 100 |
String ans = "x"; |
| 101 |
OUTER: |
| 102 |
for (; ; ) { |
| 103 |
if (true) { |
| 104 |
// :: error: (return.type.incompatible) |
| 105 |
return ans; |
| 106 |
} |
| 107 |
|
| 108 |
try { |
| 109 |
for (; cond; ) { |
| 110 |
if (true) { |
| 111 |
try { |
| 112 |
continue OUTER; |
| 113 |
} finally { |
| 114 |
ans = "x"; |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
} finally { |
| 119 |
ans = null; |
| 120 |
} |
| 121 |
ans = "x"; |
| 122 |
} |
| 123 |
} |
| 124 |
} |