RFR: 8332463: Byte conditional pattern case element dominates short constant case element
David Alayachew
davidalayachew at gmail.com
Mon May 20 22:12:44 UTC 2024
I understand the first 2 cases, but not the third. How is byte -> Integer
not unconditionally exact? What possible scenario could occur where one
would lose data?
On Mon, May 20, 2024, 4:31 AM 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
> };
> }
>
> -------------
>
> Commit messages:
> - 8332463: Byte conditional pattern case element dominates short constant
> case element
>
> Changes: https://git.openjdk.org/jdk/pull/19301/files
> Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19301&range=00
> Issue: https://bugs.openjdk.org/browse/JDK-8332463
> Stats: 104 lines in 5 files changed: 94 ins; 7 del; 3 mod
> Patch: https://git.openjdk.org/jdk/pull/19301.diff
> Fetch: git fetch https://git.openjdk.org/jdk.git
> pull/19301/head:pull/19301
>
> PR: https://git.openjdk.org/jdk/pull/19301
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20240520/ab63dd3d/attachment.htm>
More information about the compiler-dev
mailing list