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";
  26                     }
  27                     case 4: return "X"; //error: no returns from inside of the switch expression
  28                     case 5: continue;   //error: no continue out of the switch expression
  29                     case 6: continue LOOP; //error: dtto, but with a label
  30                     case 7: continue UNKNOWN; //error: unknown label
  31                     default: {
  32                         String x = "X";
  33                         x: switch (i + j) {
  34                             case 0: break ""; //error: cannot break from switch expression that is not immediatelly enclosing
  35                         }
  36                         break "X";
  37                     }
  38                 };
  39             case 1:
  40                 break "1" + undef; //error: complex value and no switch expression
  41         }
  42         }
  43         j: print(switch (i) {
  44             default: break j; //error: "j" is ambiguous (expression/label)
  45         }, 0);
  46         j2: print(switch (i) {
  47             default: break j2;
  48         }, 0);
  49         return null;
  50     }
  51 
  52 }