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

Missing unreported constraints on pattern and other case label combination

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 17
    • Fix Version/s: 17
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b31

      Backports

        Description

        Mostly based on:
        https://mail.openjdk.java.net/pipermail/compiler-dev/2021-June/017343.html

        The following should not compile:
        ---
        void testInt(Integer i) {
          switch (i) {
            case Integer o && o != null, 1: //cannot combine type patterns and constants
              System.out.println("s1");
            default:
              System.out.println("def");
          }
        }
        ---

        ---
        void testInt(Integer i) {
          switch (i) {
            case null, Integer o && o != null: //must be a type pattern
              System.out.println("s1");
            default:
              System.out.println("def");
          }
        }
        ---

        ---
            switch(selExpr) {
                case String s, null, default : //illegal combination of (type) pattern and default
            }
        ---

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  Created:
                  Updated:
                  Resolved: