1 /* 2 * @test /nodynamiccopyright/ 3 * @bug 8231827 4 * @summary Ensure that scopes arising from conditionalExpressions are handled corrected. 5 * @compile/fail/ref=BindingsTest2.out -XDrawDiagnostics -XDshould-stop.at=FLOW --enable-preview -source ${jdk.version} BindingsTest2.java 6 */ 7 public class BindingsTest2 { 8 public static boolean Ktrue() { return true; } 9 public static void main(String[] args) { 10 Object o1 = "hello"; 11 Integer in = 42; 12 Object o2 = in; 13 Object o3 = "there"; 14 15 16 if (Ktrue() ? o2 instanceof Integer x : o2 instanceof String x) { 17 x.intValue(); 18 } 19 if (Ktrue() ? o2 instanceof Integer x : true) { 20 x.intValue(); 21 } 22 23 if (o1 instanceof String s ? true : true) { 24 s.length(); 25 } 26 if (o1 instanceof String s ? true : o2 instanceof Integer s) { 27 s.length(); 28 } 29 if (o1 instanceof String s ? true : o2 instanceof Integer i) { 30 s.length(); 31 } 32 33 // Test for (e1 ? e2 : e3).T contains intersect(e1.F, e2.T) 34 if (!(o1 instanceof String s) ? true : true) { 35 s.length(); 36 } 37 if (!(o1 instanceof String s) ? (o2 instanceof Integer s) : true) { 38 s.length(); 39 } 40 if (!(o1 instanceof String s) ? (o2 instanceof Integer i) : true) { 41 s.length(); 42 i.intValue(); 43 } 44 if (!(o1 instanceof String s) ? (o1 instanceof String s2) : true) { 45 s.length(); 46 s2.length(); 47 } 48 49 50 // Test for (e1 ? e2 : e3).F contains intersect(e2.F, e3.F) 51 if (Ktrue() ? !(o2 instanceof Integer x) : !(o1 instanceof String x)){ 52 } else { 53 x.intValue(); 54 } 55 if (Ktrue() ? !(o2 instanceof Integer x) : !(o1 instanceof String s)){ 56 } else { 57 x.intValue(); 58 } 59 if (Ktrue() ? !(o2 instanceof Integer x) : !(o2 instanceof Integer x1)){ 60 } else { 61 x.intValue(); 62 x1.intValue(); 63 } 64 if (Ktrue() ? !(o2 instanceof Integer x) : false){ 65 } else { 66 x.intValue(); 67 } 68 69 // Test for (e1 ? e2 : e3).F contains intersect(e1.T, e3.F) 70 if (o1 instanceof String s ? true : !(o2 instanceof Integer s)){ 71 } else { 72 s.length(); 73 } 74 if (o1 instanceof String s ? true : !(o2 instanceof Integer i)){ 75 } else { 76 s.length(); 77 i.intValue(); 78 } 79 if (o1 instanceof String s ? true : !(o2 instanceof String s1)){ 80 } else { 81 s.length(); 82 s1.length(); 83 } 84 // Test for (e1 ? e2 : e3).F contains intersect(e1.F, e2.F) 85 if (!(o1 instanceof String s) ? !(o1 instanceof String s1) : true){ 86 } else { 87 s.length(); 88 s1.length(); 89 } 90 if (!(o1 instanceof String s) ? !(o2 instanceof Integer s) : true){ 91 } else { 92 s.length(); 93 } 94 if (!(o1 instanceof String s) ? !(o2 instanceof Integer i) : true){ 95 } else { 96 s.length(); 97 i.intValue(); 98 } 99 100 // Test for e1 ? e2: e3 - include e1.T in e2 101 if (o1 instanceof String s ? false : s.length()>0) { 102 System.out.println("done"); 103 } 104 if (o1 instanceof String s ? false : s.intValue!=0) { 105 System.out.println("done"); 106 } 107 108 // Test for e1 ? e2 : e3 - include e1.F in e3 109 if (!(o1 instanceof String s) ? s.length()>0 : false){ 110 System.out.println("done"); 111 } 112 if (!(o1 instanceof String s) ? s.intValue>0 : false){ 113 System.out.println("done"); 114 } 115 116 { 117 while (!(o1 instanceof String s)) { 118 break; 119 } 120 121 s.length(); 122 } 123 124 { 125 while (!(o1 instanceof String s)) { 126 if (false) break; 127 } 128 129 s.length(); 130 } 131 132 { 133 while (!(o1 instanceof String s)) { 134 while (true); 135 break; 136 } 137 138 s.length(); 139 } 140 141 { 142 for (; !(o1 instanceof String s); ) { 143 break; 144 } 145 146 s.length(); 147 } 148 149 { 150 for (; !(o1 instanceof String s); ) { 151 if (false) break; 152 } 153 154 s.length(); 155 } 156 157 { 158 for (; !(o1 instanceof String s); ) { 159 while (true); 160 break; 161 } 162 163 s.length(); 164 } 165 166 { 167 do { 168 break; 169 } while (!(o1 instanceof String s)); 170 171 s.length(); 172 } 173 174 { 175 do { 176 if (false) break; 177 } while (!(o1 instanceof String s)); 178 179 s.length(); 180 } 181 182 { 183 do { 184 while (true); 185 break; 186 } while (!(o1 instanceof String s)); 187 188 s.length(); 189 } 190 191 { 192 L: while (!(o1 instanceof String s)) { 193 break L; 194 } 195 196 s.length(); 197 } 198 199 { 200 L: for (; !(o1 instanceof String s); ) { 201 break L; 202 } 203 204 s.length(); 205 } 206 207 { 208 L: do { 209 break L; 210 } while (!(o1 instanceof String s)); 211 212 s.length(); 213 } 214 215 { 216 L: { 217 while (!(o1 instanceof String s)) { 218 break L; 219 } 220 221 s.length(); 222 } 223 } 224 225 { 226 L: { 227 for (; !(o1 instanceof String s); ) { 228 break L; 229 } 230 231 s.length(); 232 } 233 } 234 235 { 236 L: { 237 do { 238 break L; 239 } while (!(o1 instanceof String s)); 240 241 s.length(); 242 } 243 } 244 } 245 }