Integrated: 8332463: Byte conditional pattern case element dominates short constant case element

Aggelos Biboudis abimpoudis at openjdk.org
Wed May 22 19:51:08 UTC 2024


On Mon, 20 May 2024 08:26:43 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

> It seems that the compiler introduced a rule that does not exist in the spec. The fix is simple, and it will fix the behaviour of JDK 23 according to the spec. For example the following is accepted by JDK 22 and needs to continue to be accepted by JDK 23:
> 
> 
> public static int test() {
>     Byte i = (byte) 42;
>     return switch (i) {
>         case Byte ib   -> 1;
>         case (short) 0 -> 2; // OK - not dominated
>     };
> }
> 
> 
> Similarly for primitive type patterns:
> 
> 
> public static int test() {
>     Byte i = (byte) 42;
>     return switch (i) {
>         case Byte ib  -> 1;
>         case short s  -> 2; // Also not dominated since there is no unconditionally exact conversion from short to Byte
>     };
> }
> 
> public static int test() {
>     int i = 42;
>     return switch (i) {
>         case Integer ib -> 1;
>         case byte ip    -> 2; // Also not dominated since there is no unconditionally exact conversion from byte to Integer
>     };
> }

This pull request has now been integrated.

Changeset: c4557a7b
Author:    Aggelos Biboudis <abimpoudis at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/c4557a7b0db5b55585b4caa7cdec81e1c1093cbc
Stats:     104 lines in 5 files changed: 94 ins; 7 del; 3 mod

8332463: Byte conditional pattern case element dominates short constant case element

Reviewed-by: vromero

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

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


More information about the compiler-dev mailing list