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

Missing unreported constraints on pattern and other case label combination

XMLWordPrintable

    • b31

        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
            }
        ---

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

                Created:
                Updated:
                Resolved: