Integrated: 8309467: Pattern dominance should be adjusted

Jan Lahoda jlahoda at openjdk.org
Mon Jun 12 08:20:58 UTC 2023


On Mon, 5 Jun 2023 14:48:13 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

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

This pull request has now been integrated.

Changeset: 408cadb3
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/408cadb351eb3b3a96e81e26e1c39c89dac176ca
Stats:     80 lines in 4 files changed: 62 ins; 10 del; 8 mod

8309467: Pattern dominance should be adjusted

Reviewed-by: vromero

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

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


More information about the compiler-dev mailing list