jdk-24/test/langtools/tools/javac/switchexpr/ExpressionSwitchUnreachable.java
Joe Darcy bf2d27c5a4 8219254: Update explicit uses of latest source/target in langtools tests to a property
8219256: Update javac diags tests to use properties

Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Reviewed-by: jjg, jlahoda, darcy, iignatyev
2019-02-21 10:29:16 -08: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 ${jdk.version} 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
};
}
}