Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8268670

yield statements doesn't allow ~ or ! unary operators in expression

    XMLWordPrintable

Details

    • b27
    • generic
    • generic

    Backports

      Description

        A DESCRIPTION OF THE PROBLEM :
        JLS 14.21 for Java 16 states that

        YieldStatement:
           yield Expression ;

        but the relevant code parsing this expression does not allow expressions starting with ~ or !:
        https://github.com/openjdk/jdk/blob/5cee23a9ed0b7fe2657be7492d9c1f78fcd02ebf/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java#L2662-L2665

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile the attached source code.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The program compiles successfully
        ACTUAL -
        > javac Yield.java
        Yield.java:5: error: not a statement
                yield !1;
                ^
        Yield.java:5: error: ';' expected
                yield !1;
                     ^
        2 errors


        ---------- BEGIN SOURCE ----------
        class Yield {
          public static void main(String... args) {
            int value = switch (1) {
              default -> {
                yield !1;
              }
            };
          }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Wrap the expression in ()

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                gli Guoxiong Li
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: