1 /**
   2  * @test /nodynamiccopyright/
   3  * @bug 8214031
   4  * @summary Verify that definite assignment when true works (illegal code)
   5  * @compile/fail/ref=DefiniteAssignment2.out --enable-preview --source 12 -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: break (x = 1) == 1 || true;
  19                 default: break false;
  20             }) || x == 1;
  21         }
  22 
  23         {
  24             int x;
  25 
  26             t = (switch(a) {
  27                 case 0: break (x = 1) == 1;
  28                 default: break false;
  29             }) || x == 1;
  30         }
  31 
  32         {
  33             int x;
  34 
  35             t = (switch(a) {
  36                 case 0: x = 1; break true;
  37                 case 1: break (x = 1) == 1;
  38                 default: break false;
  39             }) || x == 1;
  40         }
  41 
  42         {
  43             int x;
  44 
  45             t = (switch(a) {
  46                 case 0: break true;
  47                 case 1: break (x = 1) == 1;
  48                 default: break false;
  49             }) && x == 1;
  50         }
  51 
  52         {
  53             int x;
  54 
  55             t = (switch(a) {
  56                 case 0: break false;
  57                 case 1: break isTrue() || (x = 1) == 1;
  58                 default: break false;
  59             }) && x == 1;
  60         }
  61 
  62         {
  63             int x;
  64 
  65             t = (switch(a) {
  66                 case 0: break false;
  67                 case 1: break isTrue() ? true : (x = 1) == 1;
  68                 default: break false;
  69             }) && x == 1;
  70         }
  71 
  72         {
  73             final int x;
  74 
  75             t = (switch(a) {
  76                 case 0: break false;
  77                 case 1: break isTrue() ? true : (x = 1) == 1;
  78                 default: break false;
  79             }) && (x = 1) == 1;
  80         }
  81     }
  82 
  83     private static boolean isTrue() {
  84         return true;
  85     }
  86 
  87 }