1 /*
2  * @test /nodynamiccopyright/
3  * @bug 8212982
4  * @summary Verify a compile-time error is produced if switch expression does not provide a value
5  * @compile/fail/ref=ExpressionSwitchFlow.out -XDrawDiagnostics ExpressionSwitchFlow.java
6  */
7 
8 public class ExpressionSwitchFlow {
test1(int i)9     private String test1(int i) {
10         return switch (i) {
11             case 0 -> {}
12             default -> { yield "other"; }
13         };
14     }
15     private String test2(int i) {
16         return switch (i) {
17             case 0 -> {
18             }
19             default -> "other";
20         };
21     }
22     private String test3(int i) {
23         return switch (i) {
24             case 0 -> {}
25             case 1 -> "";
26             default -> throw new IllegalStateException();
27         };
28     }
29     private String test4(int i) {
30         return switch (i) {
31             case 0 -> { yield "other"; }
32             default -> {}
33         };
34     }
35     private String test5(int i) {
36         return switch (i) {
37             case 0 -> "other";
38             default -> {}
39         };
40     }
41     private String test6(int i) {
42         return switch (i) {
43             case 0 -> throw new IllegalStateException();
44             case 1 -> "";
45             default -> {}
46         };
47     }
48     private String test7(int i) {
49         return switch (i) {
50             case 0: throw new IllegalStateException();
51             case 1: yield "";
52             default:
53         };
54     }
55     private String test8(int i) {
56         return switch (i) {
57             case 1: yield "";
58             case 0: i++;
59             default: {
60             }
61         };
62     }
63     private String test9(int i) {
64         return switch (i) {
65             case 1: yield "";
66             case 0:
67             default:
68                 System.err.println();
69         };
70     }
71 }
72