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

Compiler Implementation for Record Patterns

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 21
    • tools
    • None
    • source
    • minimal
    • Java API, Language construct
    • SE

      Summary

      Based on experiences with the several rounds of preview of record patterns, we propose a reduction in the feature. We also propose to make the feature final and permanent.

      Problem

      We've identified that the record patterns in enhanced for loops, introduced in the previous round of preview, may need a significant redesign, to better align with other features under consideration. The rest of the record patterns feature is, however, well vetted. We therefore propose to drop the record patterns in enhanced for loops sub-feature, and finalize the record patterns feature without this sub-feature.

      The rules for exhaustiveness of switch statements and expressions in presence of record patterns were found to not be sufficient. A new set of rules for exhaustiveness is being proposed as a solution to this problem.

      Solution

      The record patterns in enhanced for loops sub-feature will be dropped from:

      • the specification
      • the javac implementation
      • the Trees API. The relevant EnhancedForLoopTree.getVariableOrRecordPattern, EnhancedForLoopTree.getDeclarationKind and InstanceOfTree.getTestKind methods and EnhancedForLoopTree.DeclarationKind and InstanceOfTree.TestKind enums are marked as preview API, and therefore can be removed.

      The exhaustivity rules for switches in presence of record patterns will be enhanced. Please see CSR JDK-8304394 for more details.

      The rest of the record patterns feature will be made final and permanent.

      Specification

      The specification draft is available for convenience here and is attached as" 20230509 Pattern Matching for switch and Record Patterns.pdf". Please note that, for technical reasons, the specification draft also includes changes for JEP-441 (https://openjdk.org/jeps/441), which are reviewed under CSR JDK-8304394.

      The specdiff of API changes is available here and is attached as specdiff.00.zip. Please note that, for technical reasons, the specdiff also includes changes for JEP-441 (https://openjdk.org/jeps/441), which are reviewed under CSR JDK-8304394.

      The feature will be made final and permanent.

            jlahoda Jan Lahoda
            gbierman Gavin Bierman
            Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: