<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<font size="4"><font face="monospace">We have two not-great choices
here:<br>
<br>
- Treat otherwise-boring switches on long/float/double/boolean
(and their boxes) as legacy primitive switches, omitting the
enhanced exhaustiveness checking;<br>
- Treat switching on float/double/boolean and their boxes as
triggering the enhanced exhaustiveness checking. <br>
<br>
It is unfortunate that we have to have a carve-out for "old"
switches, because this means an irregular and
possibly-surprising boundary in the language, which users will
have to learn (sometimes learning the hard way.) But we do, and
we accepted it as the cost of turbo-charging switch (new
selector types, new case labels, better exhaustiveness, guards,
null support, etc.) Ideally we will have a path to gently
guiding users away from the legacy behavior to the point where
we are eventually comfortable promoting some warnings to errors,
and this issue goes away, but that will surely take a long time,
and I won't dwell on it here.<br>
<br>
In the meantime, we have a choice of "which of these two
irregular boundaries do we want the user to reason about":<br>
<br>
- A statement switch is exempt from exhaustiveness checking if
it does not use patterns, null cases, guards, or switch on
anything other than {byte,char,short,int}, their boxes, enums,
or strings, or<br>
</font></font><br>
<font size="4"><font face="monospace"><font size="4"><font face="monospace"> - A statement switch is exempt from
exhaustiveness checking if it does not use patterns, null
cases, guards, or switch on anything other than a primitive,
their boxes, enums, or strings.<br>
<br>
Remi makes the argument for the first path, on the basis of
"let's freeze the legacy behavior to the legacy rules."
This is a reasonable argument. However, the opposite
argument is also reasonable; that "typical user intuition"
about "old switch" is closer to "primitives, boxes, enums,
and strings", and that allowing the remaining primitive
types to fit into the old model may minimize cognitive load
on the user. (It is easier to keep track of "primitives"
than "the primitives that we thought were reasonable to
switch over in 1995", since that set is kind of arbitrarily
chosen.)<br>
<br>
So while I don't have an answer, I do think that both
possible answers have merit :)<br>
<br>
<br>
</font></font><br>
</font></font><br>
<div class="moz-cite-prefix">On 10/25/2023 4:50 AM, Remi Forax
wrote:<br>
</div>
<blockquote type="cite" cite="mid:1561586376.34535743.1698223822038.JavaMail.zimbra@univ-eiffel.fr">
<div id="zimbraEditorContainer" style="font-family: arial,
helvetica, sans-serif; font-size: 12pt; color: #000000" class="29">
<div><br>
</div>
<div><br>
</div>
<hr id="zwchr" data-marker="__DIVIDER__">
<div data-marker="__HEADERS__">
<blockquote style="border-left:2px solid
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;"><b>From:
</b>"Angelos Bimpoudis" <a class="moz-txt-link-rfc2396E" href="mailto:angelos.bimpoudis@oracle.com"><angelos.bimpoudis@oracle.com></a><br>
<b>To: </b>"amber-spec-experts"
<a class="moz-txt-link-rfc2396E" href="mailto:amber-spec-experts@openjdk.org"><amber-spec-experts@openjdk.org></a><br>
<b>Cc: </b>"Yuriy Maslyanko"
<a class="moz-txt-link-rfc2396E" href="mailto:yuriy.maslyanko@oracle.com"><yuriy.maslyanko@oracle.com></a><br>
<b>Sent: </b>Wednesday, October 25, 2023 12:49:18 AM<br>
<b>Subject: </b>Fw: JEP 455: Non-enhanced switch statements<br>
</blockquote>
</div>
<div>
<style style="display:none;">P {margin-top:0;margin-bottom:0;}</style></div>
<div data-marker="__QUOTED_TEXT__">
<blockquote style="border-left:2px solid
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div style="font-family: "Segoe UI", "Segoe
UI ", "Helvetica Neue", sans-serif;
font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
Hello all!</div>
</blockquote>
<div><br>
</div>
<div>Hello Angelos,<br data-mce-bogus="1">
</div>
<div><br data-mce-bogus="1">
</div>
<blockquote style="border-left:2px solid
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div style="font-family: "Segoe UI", "Segoe
UI ", "Helvetica Neue", sans-serif;
font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<br>
</div>
<div style="font-family: "Segoe UI", "Segoe
UI ", "Helvetica Neue", sans-serif;
font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-family: Calibri, sans-serif; display:
inline !important; background-color: rgb(255, 255,
255);" class="ContentPasted0">Yuriy pointed out a valid
point.</span><br>
</div>
<div style="font-family: "Segoe UI", "Segoe
UI ", "Helvetica Neue", sans-serif;
font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-family: Calibri, sans-serif; display:
inline !important; background-color: rgb(255, 255,
255);" class="ContentPasted0"><br>
</span></div>
<div style="font-family: "Segoe UI", "Segoe
UI ", "Helvetica Neue", sans-serif;
font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-family: Calibri, sans-serif; display:
inline !important; background-color: rgb(255, 255,
255);" class="ContentPasted0">1) Should we treat
float/double/boolean/longs as a new addition to the
<span style="display: inline !important;
background-color: rgb(255, 255, 255);">non-enhanced</span>
switch (old switch) and support anything new that comes
with that?</span></div>
<div style="font-family: "Segoe UI", "Segoe
UI ", "Helvetica Neue", sans-serif;
font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof">
<span style="font-family: Calibri, sans-serif; display:
inline !important; background-color: rgb(255, 255,
255);" class="ContentPasted0"><br>
</span></div>
<div style="font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof"><font face="Calibri, sans-serif">or</font></div>
<div style="font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof"><font face="Calibri, sans-serif"><br>
</font></div>
<div style="font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof"><font face="Calibri, sans-serif">2)
Should we treat those data types equally with all the
pre-existing ones?</font></div>
<div style="font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof"><font face="Calibri, sans-serif"><br>
</font></div>
<div style="font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof"><font face="Calibri, sans-serif">I
am strongly in favour of the
<span style="display: inline !important;
background-color: rgb(255, 255, 255);">2)</span> for
the shake of symmetry and uniformity in what the user
will assume, thus I will fix the bug.</font></div>
<div style="font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof"><font face="Calibri, sans-serif"><br>
</font></div>
<div style="font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof"><font face="Calibri, sans-serif">What
do others think?</font></div>
</blockquote>
<div><br>
</div>
<div>We have already discuss that, when we have introduce the
switch on objects.</div>
<div>The question is not what our current users will assume
now but how the whole semantics of switch will be see let
say 5 years from now, when people are used to use the switch
on objects.<br>
</div>
<div>The old switch is not a feature used a lot, we expected
the new switch on objects to be used a lot more, so at some
points, most of the switches will be switches on object so
the semantics of the old switch will be the outlier.</div>
<div>So the switch on float/double should behave like on
objects, i.e. be hexaustive by default.</div>
<div>It's the same reason why adding a "case null" or a
"where" condition transforms the switch to the new
semantics.<br data-mce-bogus="1">
</div>
<div><br data-mce-bogus="1">
</div>
<div>And there is another reason to make the switch on
float/double exhaustive, the matching of a cases on
primitive types can be partial, when we discussed that
feature this is was obvious for some of us (me included).</div>
<div>By making the switch exhaustive, we actually help users
to understand the actual semantics, because the compiler
will requires a "default" if the pattern matching is not
total.<br data-mce-bogus="1">
</div>
<div><br data-mce-bogus="1">
</div>
<div>regards,<br data-mce-bogus="1">
</div>
<div>Rémi</div>
<div><br data-mce-bogus="1">
</div>
<blockquote style="border-left:2px solid
#1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;">
<div style="font-family: "Segoe UI", "Segoe
UI ", "Helvetica Neue", sans-serif;
font-size: 11pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:
11pt; color: rgb(0, 0, 0);" face="Calibri, sans-serif"><b>From:</b>
Yuriy Maslyanko <a class="moz-txt-link-rfc2396E" href="mailto:yuriy.maslyanko@oracle.com"><yuriy.maslyanko@oracle.com></a><br>
<b>Sent:</b> 24 October 2023 21:57<br>
<b>To:</b> Angelos Bimpoudis
<a class="moz-txt-link-rfc2396E" href="mailto:angelos.bimpoudis@oracle.com"><angelos.bimpoudis@oracle.com></a><br>
<b>Cc:</b> <a class="moz-txt-link-abbreviated" href="mailto:compiler-dev@openjdk.org">compiler-dev@openjdk.org</a>
<a class="moz-txt-link-rfc2396E" href="mailto:compiler-dev@openjdk.org"><compiler-dev@openjdk.org></a><br>
<b>Subject:</b> JEP 455: Non-enhanced switch statements</font>
<div> </div>
</div>
<div style="word-wrap:break-word" lang="EN-US">
<div class="x_WordSection1">
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
Hi Angelos,</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
Section 14.11.2 of <a href="https://cr.openjdk.org/~abimpoudis/instanceof/jep443-20231010/specs/instanceof-jls.html#jls-14.11.2" id="OWA8a7ff157-bb46-c408-0d8c-3100cc911996" class="OWAAutoLink moz-txt-link-freetext" target="_blank" moz-do-not-send="true">
https://cr.openjdk.org/~abimpoudis/instanceof/jep443-20231010/specs/instanceof-jls.html#jls-14.11.2</a>
has this note:</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri,
sans-serif;margin-left:.5in">
For compatibility reasons, <code style="font-family:
"Courier New";"><span style="font-size:10.0pt">switch</span></code>
statements that are not enhanced
<code style="font-family: "Courier New";"><span style="font-size:10.0pt">switch</span></code>
statements are not required to be exhaustive.</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
Noticed that if the switch selector statement is
float/double/boolean (in this case it’s a non-enhanced
switch statement), the code shown below fails with
“error: the switch statement does not cover all
possible input values”:</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
static boolean check = false;</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
public static boolean testMethod() {</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
double v1 = 1d;</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
switch ( v1 ) {</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
case 1d:</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
check = true;</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
break;</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
}</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
return check;</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
}</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
</p>
<p class="x_MsoNormal" style="margin: 0in; font-size:
11pt; font-family: Calibri, sans-serif;">
<br>
</p>
</div>
</div>
<br>
</blockquote>
</div>
</div>
</blockquote>
<br>
</body>
</html>