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