Fwd: Use of "assignment compatible" in the switch statement specifications
Brian Goetz
brian.goetz at oracle.com
Wed Aug 17 15:15:20 UTC 2022
This one got stuck in the -comments moderation queue for a while.
-------- Forwarded Message --------
Subject: Use of "assignment compatible" in the switch statement
specifications
Date: Wed, 6 Jul 2022 22:29:32 +0000
From: Robbe Pincket <robbepincket at live.be>
To: jls-jvms-spec-comments at openjdk.java.net
<jls-jvms-spec-comments at openjdk.java.net>,
amber-spec-comments at openjdk.org <amber-spec-comments at openjdk.org>
Hi experts
A while back I was reading the new amber spec on switch pattern
matching, and read something that felt off, but after checking the
normal spec, I noticed the issue existed there too.
It was late when I sent my review of the amber spec to their group, so I
wanted to sent this the day after but I managed to forget it.
In 5.2, the concept of "assignment compatible" is introduced:
> If the type of an expression can be converted to the type of a variable by assignment
conversion, we say the expression (or its value) is assignable to the
variable or, equivalently, that the type of the expression is assignment
compatible with the type of the variable.
It is a useful concept that is used a total of 16 times in the spec for
java 18 (and the current 19 spec).
Although this concept is introduced as a relation between two types, in
the switch statement specifications (14.11) the following appears:
> 14.11.1 Switch Blocks
> ...
> The switch block of a switch statement or a switch expression is compatible with
the type of the selector expression, T, if both of the following are true:
> * If T is not an enum type, then **every case constant associated with the switch
block is assignment compatible with T (§5.2)**.
> * ...
Here the relation is used between a constant and a type, which seems to
be incorrect.
For the Amber experts, this section has been rewritten due to there
being more valid possible selector types, but the issue remains:
> A case constant c is switch compatible with a type T where T is either char, byte,
short, int, Character, Byte, Short, Integer, or String if c is
assignment compatible with T (5.2).
Greetings
Robbe Pincket
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-experts/attachments/20220817/7b6e1439/attachment-0001.htm>
More information about the amber-spec-experts
mailing list