< prev index next >

test/langtools/tools/javac/switchexpr/ExpressionSwitchBreaks2.java

Print this page


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Check behavior for invalid breaks.
   5  * @compile/fail/ref=ExpressionSwitchBreaks2.out -XDrawDiagnostics --enable-preview -source 12 ExpressionSwitchBreaks2.java
   6  */
   7 
   8 public class ExpressionSwitchBreaks2 {
   9     private String print(int i, int j) {
  10         LOOP: while (true) {
  11         OUTER: switch (i) {
  12             case 0:
  13                 return switch (j) {
  14                     case 0:
  15                         break "0-0";
  16                     case 1:
  17                         break ; //error: missing value
  18                     case 2:
  19                         break OUTER; //error: jumping outside of the switch expression
  20                     case 3: {
  21                         int x = -1;
  22                         x: switch (i + j) {
  23                             case 0: break x; //error: cannot disambiguate, wrong type as well
  24                         }
  25                         break "X";


   1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Check behavior for invalid breaks.
   5  * @compile/fail/ref=ExpressionSwitchBreaks2.out -XDrawDiagnostics --enable-preview -source 13 ExpressionSwitchBreaks2.java
   6  */
   7 
   8 public class ExpressionSwitchBreaks2 {
   9     private String print(int i, int j) {
  10         LOOP: while (true) {
  11         OUTER: switch (i) {
  12             case 0:
  13                 return switch (j) {
  14                     case 0:
  15                         break "0-0";
  16                     case 1:
  17                         break ; //error: missing value
  18                     case 2:
  19                         break OUTER; //error: jumping outside of the switch expression
  20                     case 3: {
  21                         int x = -1;
  22                         x: switch (i + j) {
  23                             case 0: break x; //error: cannot disambiguate, wrong type as well
  24                         }
  25                         break "X";


< prev index next >