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 --enable-preview -source 13 -XDrawDiagnostics ExpressionSwitchFlow.java 6 */ 7 8 public class ExpressionSwitchFlow { 9 private String test1(int i) { 10 return switch (i) { 11 case 0 -> {} 12 default -> { break "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 default -> throw new IllegalStateException(); 26 }; 27 } 28 private String test4(int i) { 29 return switch (i) { 30 case 0 -> { break "other"; } 31 default -> {} 32 }; 33 } 34 private String test5(int i) { 35 return switch (i) { 36 case 0 -> "other"; 37 default -> {} 38 }; 39 } 40 private String test6(int i) { 41 return switch (i) { 42 case 0 -> throw new IllegalStateException(); 43 default -> {} 44 }; 45 } 46 private String test7(int i) { 47 return switch (i) { 48 case 0: throw new IllegalStateException(); 49 default: 50 }; 51 } 52 private String test8(int i) { 53 return switch (i) { 54 case 0: i++; 55 default: { 56 } 57 }; 58 } 59 private String test9(int i) { 60 return switch (i) { 61 case 0: 62 default: 63 System.err.println(); 64 }; 65 } 66 }