|
1 /* |
|
2 * @test /nodynamiccopyright/ |
|
3 * @bug 8231827 |
|
4 * @summary Basic tests for bindings from instanceof - tests for merging pattern variables |
|
5 * @compile/fail/ref=BindingsTest1Merging.out -XDrawDiagnostics --enable-preview -source ${jdk.version} BindingsTest1Merging.java |
|
6 */ |
|
7 |
|
8 public class BindingsTest1Merging { |
|
9 public static boolean Ktrue() { return true; } |
|
10 public static void main(String[] args) { |
|
11 Object o1 = "hello"; |
|
12 Integer i = 42; |
|
13 Object o2 = i; |
|
14 Object o3 = "there"; |
|
15 |
|
16 // Test for e1 && e2.F = intersect(e1.F, e2.F) |
|
17 if (!(o1 instanceof String s) && !(o1 instanceof String s)) { |
|
18 |
|
19 } else { |
|
20 s.length(); |
|
21 } |
|
22 |
|
23 // Test for (e1 || e2).T = intersect(e1.T, e2.T) |
|
24 if (o1 instanceof String s || o3 instanceof String s){ |
|
25 System.out.println(s); // ? |
|
26 } |
|
27 |
|
28 // Test for (e1 ? e2 : e3).T contains intersect(e2.T, e3.T) |
|
29 if (Ktrue() ? o2 instanceof Integer x : o2 instanceof Integer x) { |
|
30 x.intValue(); |
|
31 } |
|
32 |
|
33 // Test for (e1 ? e2 : e3).T contains intersect(e1.T, e3.T) |
|
34 if (o1 instanceof String s ? true : o1 instanceof String s) { |
|
35 s.length(); |
|
36 } |
|
37 |
|
38 // Test for (e1 ? e2 : e3).T contains intersect(e1.F, e2.T) |
|
39 if (!(o1 instanceof String s) ? (o1 instanceof String s) : true) { |
|
40 s.length(); |
|
41 } |
|
42 |
|
43 // Test for (e1 ? e2 : e3).F contains intersect(e2.F, e3.F) |
|
44 if (Ktrue() ? !(o2 instanceof Integer x) : !(o2 instanceof Integer x)){ |
|
45 } else { |
|
46 x.intValue(); |
|
47 } |
|
48 |
|
49 // Test for (e1 ? e2 : e3).F contains intersect(e1.T, e3.F) |
|
50 if (o1 instanceof String s ? true : !(o1 instanceof String s)){ |
|
51 } else { |
|
52 s.length(); |
|
53 } |
|
54 |
|
55 // Test for (e1 ? e2 : e3).F contains intersect(e1.F, e2.F) |
|
56 if (!(o1 instanceof String s) ? !(o1 instanceof String s) : true){ |
|
57 } else { |
|
58 s.length(); |
|
59 } |
|
60 |
|
61 L3: { |
|
62 if ((o1 instanceof String s) || (o3 instanceof String s)) { |
|
63 s.length(); |
|
64 } else { |
|
65 break L3; |
|
66 } |
|
67 s.length(); |
|
68 } |
|
69 |
|
70 System.out.println("BindingsTest1Merging complete"); |
|
71 } |
|
72 } |