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