1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Verify reachability in switch expressions.
   5  * @compile/fail/ref=ExpressionSwitchUnreachable.out -XDrawDiagnostics --enable-preview -source 12 ExpressionSwitchUnreachable.java
   6  */
   7 
   8 public class ExpressionSwitchUnreachable {
   9 
  10     public static void main(String[] args) {
  11         int z = 42;
  12         int i = switch (z) {
  13             case 0 -> {
  14                 break 42;
  15                 System.out.println("Unreachable");  //Unreachable
  16             }
  17             default -> 0;
  18         };
  19         i = switch (z) {
  20             case 0 -> {
  21                 break 42;
  22                 break 42; //Unreachable
  23             }
  24             default -> 0;
  25         };
  26         i = switch (z) {
  27             case 0:
  28                 System.out.println("0");
  29                 break 42;
  30                 System.out.println("1");    //Unreachable
  31             default : break 42;
  32         };
  33         i = switch (z) {
  34             case 0 -> 42;
  35             default -> {
  36                 break 42;
  37                 System.out.println("Unreachable"); //Unreachable
  38             }
  39         };
  40         i = switch (z) {
  41             case 0: break 42;
  42             default:
  43                 System.out.println("0");
  44                 break 42;
  45                 System.out.println("1");    //Unreachable
  46         };
  47         i = switch (z) {
  48             case 0:
  49             default:
  50                 System.out.println("0");
  51                 break 42;
  52                 System.out.println("1");    //Unreachable
  53         };
  54     }
  55 
  56 
  57 }