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
|
/*
* @test /nodynamiccopyright/
* @bug 8231827
* @summary Basic tests for bindings from instanceof - tests for merging pattern variables
* @compile/fail/ref=BindingsTest1Merging.out -XDrawDiagnostics BindingsTest1Merging.java
*/
public class BindingsTest1Merging {
public static boolean Ktrue() { return true; }
public static void meth() {
Object o1 = "hello";
Integer i = 42;
Object o2 = i;
Object o3 = "there";
// Test for e1 && e2.F = intersect(e1.F, e2.F)
if (!(o1 instanceof String s) && !(o1 instanceof String s)) {
} else {
s.length();
}
// Test for (e1 || e2).T = intersect(e1.T, e2.T)
if (o1 instanceof String s || o3 instanceof String s){
System.out.println(s); // ?
}
// Test for (e1 ? e2 : e3).T contains intersect(e2.T, e3.T)
if (Ktrue() ? o2 instanceof Integer x : o2 instanceof Integer x) {
x.intValue();
}
// Test for (e1 ? e2 : e3).T contains intersect(e1.T, e3.T)
if (o1 instanceof String s ? true : o1 instanceof String s) {
s.length();
}
// Test for (e1 ? e2 : e3).T contains intersect(e1.F, e2.T)
if (!(o1 instanceof String s) ? (o1 instanceof String s) : true) {
s.length();
}
// Test for (e1 ? e2 : e3).F contains intersect(e2.F, e3.F)
if (Ktrue() ? !(o2 instanceof Integer x) : !(o2 instanceof Integer x)){
} else {
x.intValue();
}
// Test for (e1 ? e2 : e3).F contains intersect(e1.T, e3.F)
if (o1 instanceof String s ? true : !(o1 instanceof String s)){
} else {
s.length();
}
// Test for (e1 ? e2 : e3).F contains intersect(e1.F, e2.F)
if (!(o1 instanceof String s) ? !(o1 instanceof String s) : true){
} else {
s.length();
}
L3: {
if ((o1 instanceof String s) || (o3 instanceof String s)) {
s.length();
} else {
break L3;
}
s.length();
}
System.out.println("BindingsTest1Merging complete");
}
}
|