[jdk17] RFR: 8268670: yield statements doesn't allow ~ or ! unary operators in expression

Guoxiong Li gli at openjdk.java.net
Mon Jun 14 16:01:50 UTC 2021


Hi all,

Currently, the javac can't address the `yield` statement with `~` or `!` unary operators.
Javac will report the unexpected error messages when compiling the following two demos.


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



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


This patch fixes it and adds the corresponding tests.
Thanks for taking the time to review.

Best Regards,
-- Guoxiong

-------------

Commit messages:
 - 8268670: yield statements doesn't allow ~ or ! unary operators in expression

Changes: https://git.openjdk.java.net/jdk17/pull/46/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk17&pr=46&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8268670
  Stats: 24 lines in 2 files changed: 23 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk17/pull/46.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/46/head:pull/46

PR: https://git.openjdk.java.net/jdk17/pull/46


More information about the compiler-dev mailing list