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