jdk-24/test/langtools/tools/javac/switchexpr/ExpressionSwitchUnreachable.java
Jan Lahoda b3b644438e 8206986: Compiler support for Switch Expressions (Preview)
8207405: Compiler Tree API support for Switch Expressions (Preview)

Support for switch expression, switch with rules and multiple constants for cases.

Reviewed-by: jjg, mcimadamore, vromero
2018-08-29 09:36:17 +02:00

58 lines
1.5 KiB
Java

/*
* @test /nodynamiccopyright/
* @bug 8206986
* @summary Verify reachability in switch expressions.
* @compile/fail/ref=ExpressionSwitchUnreachable.out -XDrawDiagnostics --enable-preview -source 12 ExpressionSwitchUnreachable.java
*/
public class ExpressionSwitchUnreachable {
public static void main(String[] args) {
int z = 42;
int i = switch (z) {
case 0 -> {
break 42;
System.out.println("Unreachable"); //Unreachable
}
default -> 0;
};
i = switch (z) {
case 0 -> {
break 42;
break 42; //Unreachable
}
default -> 0;
};
i = switch (z) {
case 0:
System.out.println("0");
break 42;
System.out.println("1"); //Unreachable
default : break 42;
};
i = switch (z) {
case 0 -> 42;
default -> {
break 42;
System.out.println("Unreachable"); //Unreachable
}
};
i = switch (z) {
case 0: break 42;
default:
System.out.println("0");
break 42;
System.out.println("1"); //Unreachable
};
i = switch (z) {
case 0:
default:
System.out.println("0");
break 42;
System.out.println("1"); //Unreachable
};
}
}