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

Wrong inference in switch expression with "null" arm

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 16
    • 14, 15, 16
    • tools
    • None
    • b22

    Description

      This code does not compile:

      interface I {
          void m();
      }
      interface I1 extends I {}
      interface I2 extends I {}

      static void n(I1 i1, I2 i2, int s) {
          var i_ = switch (s) { //<- Object
              case 1 -> i1;
              case 2 -> null;
              default -> i2;
          };
          if (i_ != null) {
              i_.m(); //cannot find symbol m()
          }
      }

      Javac infers Object instead of I, suggesting some issues around handling of `null` in switch expression.

      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              mcimadamore Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: