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

Compilation error thrown while doing a boxing conversion on selector expression

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 18
    • Fix Version/s: 18
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b27

      Description

      The below code should compile successfully.

      class PatternTest {
          public static void main(String[] args) {

              int selExpr = 1;
              int retval = switch (selExpr) {
                  case Integer p -> 6;
                  default -> 1;
              };
              System.out.println(retval);
          }
      }

      However, the compilation throws error with JDK 18 b25:

      jdk-18/bin/javac --enable-preview -source 18 PatternTest.java
      PatternTest.java:6: error: bad operand type int for unary operator '<*nullchk*>'
              int retval = switch (selExpr) {
                                  ^
      Note: PatternTest.java uses preview features of Java SE 18.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jlahoda Jan Lahoda
              Reporter:
              vkhatri Vinod Khatri
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: