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
|
/*
* @test /nodynamiccopyright/
* @bug 8206986 8226510
* @summary Verify than a switch that does not yield a value is rejected.
* @compile/fail/ref=EmptySwitch.out -XDrawDiagnostics -XDshould-stop.at=FLOW EmptySwitch.java
*/
public class EmptySwitch {
private void print(EmptySwitchEnum t) {
(switch (t) {
}).toString();
(switch (t) {
default -> throw new IllegalStateException();
}).toString();
(switch (t) {
default: throw new IllegalStateException();
}).toString();
(switch (0) {
case 0: yield "";
default:
}).toString();
(switch (0) {
case 0 -> { yield ""; }
default -> { }
}).toString();
}
enum EmptySwitchEnum {
}
}
|