2018-08-29 07:36:17 +00:00
|
|
|
/*
|
|
|
|
* @test /nodynamiccopyright/
|
|
|
|
* @bug 8206986
|
|
|
|
* @summary Verify reachability in switch expressions.
|
2019-11-12 06:32:13 +00:00
|
|
|
* @compile/fail/ref=ExpressionSwitchUnreachable.out -XDrawDiagnostics ExpressionSwitchUnreachable.java
|
2018-08-29 07:36:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
public class ExpressionSwitchUnreachable {
|
|
|
|
|
2023-01-17 04:43:40 +00:00
|
|
|
public static void meth() {
|
2018-08-29 07:36:17 +00:00
|
|
|
int z = 42;
|
|
|
|
int i = switch (z) {
|
|
|
|
case 0 -> {
|
2019-06-10 03:09:52 +00:00
|
|
|
yield 42;
|
2018-08-29 07:36:17 +00:00
|
|
|
System.out.println("Unreachable"); //Unreachable
|
|
|
|
}
|
|
|
|
default -> 0;
|
|
|
|
};
|
|
|
|
i = switch (z) {
|
|
|
|
case 0 -> {
|
2019-06-10 03:09:52 +00:00
|
|
|
yield 42;
|
|
|
|
yield 42; //Unreachable
|
2018-08-29 07:36:17 +00:00
|
|
|
}
|
|
|
|
default -> 0;
|
|
|
|
};
|
|
|
|
i = switch (z) {
|
|
|
|
case 0:
|
|
|
|
System.out.println("0");
|
2019-06-10 03:09:52 +00:00
|
|
|
yield 42;
|
2018-08-29 07:36:17 +00:00
|
|
|
System.out.println("1"); //Unreachable
|
2019-06-10 03:09:52 +00:00
|
|
|
default : yield 42;
|
2018-08-29 07:36:17 +00:00
|
|
|
};
|
|
|
|
i = switch (z) {
|
|
|
|
case 0 -> 42;
|
|
|
|
default -> {
|
2019-06-10 03:09:52 +00:00
|
|
|
yield 42;
|
2018-08-29 07:36:17 +00:00
|
|
|
System.out.println("Unreachable"); //Unreachable
|
|
|
|
}
|
|
|
|
};
|
|
|
|
i = switch (z) {
|
2019-06-10 03:09:52 +00:00
|
|
|
case 0: yield 42;
|
2018-08-29 07:36:17 +00:00
|
|
|
default:
|
|
|
|
System.out.println("0");
|
2019-06-10 03:09:52 +00:00
|
|
|
yield 42;
|
2018-08-29 07:36:17 +00:00
|
|
|
System.out.println("1"); //Unreachable
|
|
|
|
};
|
|
|
|
i = switch (z) {
|
|
|
|
case 0:
|
|
|
|
default:
|
|
|
|
System.out.println("0");
|
2019-06-10 03:09:52 +00:00
|
|
|
yield 42;
|
2018-08-29 07:36:17 +00:00
|
|
|
System.out.println("1"); //Unreachable
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|