RFR: 8309469: Pattern dominance should be adjusted

Jan Lahoda jlahoda at openjdk.org
Mon Jun 5 14:54:20 UTC 2023


Currently, when a switch contains both patterns and constant labels, any pattern case dominates the constant label. E.g. the following example currently produces a compile-time error:

switch (...) {
    case Integer i when i == 0 -> {}
    case 1 -> {} //dominated by the preceding case
    case Integer i -> {}
}


But, the rules are now (to be) relaxed in the spec, so that guarded cases (with patterns) don't dominate cases with constant labels. I.e. the above example is supposed to compile and run fine.

This PR is implementing this change - when checking patter-constant dominance, we only consider unguarded cases.

-------------

Commit messages:
 - Fixing test.
 - 8309469: Pattern dominance should be adjusted

Changes: https://git.openjdk.org/jdk/pull/14314/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=14314&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8309469
  Stats: 80 lines in 4 files changed: 62 ins; 10 del; 8 mod
  Patch: https://git.openjdk.org/jdk/pull/14314.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14314/head:pull/14314

PR: https://git.openjdk.org/jdk/pull/14314


More information about the compiler-dev mailing list