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

Pattern dominance should be adjusted

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 21, 22
    • tools
    • None
    • source
    • minimal
    • Language construct
    • SE

      Summary

      Rules for dominance between cases with patterns and cases with constant labels are relaxed so that unguarded cases do not dominate cases with constant labels.

      Problem

      The current dominance rules are relatively strict for cases with constant labels - any case with (unconditional) pattern dominates any case with a constant label. This is inconsistent with dominance between cases with patterns, where guarded cases don't dominate other cases with patterns.

      Solution

      The proposal is to make the rules for dominance more consistent, in particular, so that guarded cases with patterns don't dominate any other case labels, including cases with constant labels.

      Specification

      This existing normative text in the specification:

      • A case label with a case constant c is dominated if one of the following holds:
        • c is a constant expression of a primitive type S, and there is a preceding case label in the switch block with a case pattern p, where p is unconditional for the wrapper class of S.
        • c is a constant expression of a reference type T, and there is a preceding case label in the switch block with a case pattern p, where p is unconditional for the type T.
        • c is an enum constant of type T, and there is a preceding case label in the switch block with a case pattern p, where p is unconditional for the type T.

      Is replaced with the following text:

      • A case label with a case constant c is dominated if one of the following holds:

        • c is a constant expression of a primitive type S, and there is a preceding case label in the switch block with an unguarded case pattern p, where p is unconditional for the wrapper class of S.

        • c is a constant expression of a reference type T, and there is a preceding case label in the switch block with an unguarded case pattern p, where p is unconditional for the type T.

        • c is an enum constant of type T, and there is a preceding case label in the switch block with an unguarded case pattern p, where p is unconditional for the type T.

            jlahoda Jan Lahoda
            jlahoda Jan Lahoda
            Gavin Bierman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: