1 /**
   2  * @test /nodynamiccopyright/
   3  * @bug 8214031
   4  * @summary Verify that definite assignment when true works (illegal code)
   5  * @compile/fail/ref=DefiniteAssignment2.out -XDrawDiagnostics DefiniteAssignment2.java
   6  */
   7 public class DefiniteAssignment2 {
   8 
   9     public static void main(String[] args) {
  10         int a = 0;
  11         boolean b = true;
  12         boolean t;
  13 
  14         {
  15             int x;
  16 
  17             t = (b && switch(a) {
  18                 case 0: yield (x = 1) == 1 || true;
  19                 default: yield false;
  20             }) || x == 1;
  21         }
  22 
  23         {
  24             int x;
  25 
  26             t = (switch(a) {
  27                 case 0: yield (x = 1) == 1;
  28                 default: yield false;
  29             }) || x == 1;
  30         }
  31 
  32         {
  33             int x;
  34 
  35             t = (switch(a) {
  36                 case 0: x = 1; yield true;
  37                 case 1: yield (x = 1) == 1;
  38                 default: yield false;
  39             }) || x == 1;
  40         }
  41 
  42         {
  43             int x;
  44 
  45             t = (switch(a) {
  46                 case 0: yield true;
  47                 case 1: yield (x = 1) == 1;
  48                 default: yield false;
  49             }) && x == 1;
  50         }
  51 
  52         {
  53             int x;
  54 
  55             t = (switch(a) {
  56                 case 0: yield false;
  57                 case 1: yield isTrue() || (x = 1) == 1;
  58                 default: yield false;
  59             }) && x == 1;
  60         }
  61 
  62         {
  63             int x;
  64 
  65             t = (switch(a) {
  66                 case 0: yield false;
  67                 case 1: yield isTrue() ? true : (x = 1) == 1;
  68                 default: yield false;
  69             }) && x == 1;
  70         }
  71 
  72         {
  73             final int x;
  74 
  75             t = (switch(a) {
  76                 case 0: yield false;
  77                 case 1: yield isTrue() ? true : (x = 1) == 1;
  78                 default: yield false;
  79             }) && (x = 1) == 1;
  80         }
  81     }
  82 
  83     private static boolean isTrue() {
  84         return true;
  85     }
  86 
  87 }