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

javac does not recognize variable assigned in switch expression as DA

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 13
    • 12, 13
    • tools
    • None
    • b15

    Description

      As reported here:
      http://mail.openjdk.java.net/pipermail/amber-dev/2019-March/004204.html

      javac fails to compile this code:
      ---
      enum MyEnum {
          X, Y;
           
          public static void main(String[] args) {
               MyEnum myEnum = MyEnum.X;
               int o;
               var f = switch(myEnum) {
                   case X -> o = 5;
                   case Y -> o = 10;
                   // automatic exception
               };
               System.out.println(o);
           }
      }
      ---

      ---
      $ javac --enable-preview --source 13 /tmp/MyEnum.java
      /tmp/MyEnum.java:12: error: variable o might not have been initialized
               System.out.println(o);
                                  ^
      Note: /tmp/MyEnum.java uses preview language features.
      Note: Recompile with -Xlint:preview for details.
      1 error
      ---

      Attachments

        Activity

          People

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: