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