<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: "Segoe UI", "Segoe UI Web (West European)", "Helvetica Neue", sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof ContentPasted0">
Thank you, Remi, we are on it! <span id="🚀">🚀</span></div>
<div style="font-family: "Segoe UI", "Segoe UI Web (West European)", "Helvetica Neue", sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof ContentPasted0">
<br>
</div>
<div style="font-family: "Segoe UI", "Segoe UI Web (West European)", "Helvetica Neue", sans-serif; font-size: 11pt; color: rgb(0, 0, 0);" class="elementToProof ContentPasted0">
<a href="https://bugs.openjdk.org/browse/JDK-8317300" id="LPlnk989402" class="OWAAutoLink">https://bugs.openjdk.org/browse/JDK-8317300</a></div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Remi Forax <forax@univ-mlv.fr><br>
<b>Sent:</b> 27 September 2023 15:59<br>
<b>To:</b> Angelos Bimpoudis <angelos.bimpoudis@oracle.com><br>
<b>Cc:</b> Clément BOUDEREAU <cboudereau@gmail.com>; Gavin Bierman <gavin.bierman@oracle.com>; Brian Goetz <brian.goetz@oracle.com>; Tagir Valeev <amaembo@gmail.com>; amber-dev <amber-dev@openjdk.org>; amber-spec-experts <amber-spec-experts@openjdk.org><br>
<b>Subject:</b> Re: [External] : Re: New candidate JEP: 456: Unnamed Variables and Patterns</font>
<div> </div>
</div>
<div>
<div style="font-family:arial,helvetica,sans-serif; font-size:12pt; color:#000000">
<div><br>
</div>
<div><br>
</div>
<hr id="x_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" <angelos.bimpoudis@oracle.com><br>
<b>To: </b>"Clément BOUDEREAU" <cboudereau@gmail.com>, "Gavin Bierman" <gavin.bierman@oracle.com><br>
<b>Cc: </b>"Brian Goetz" <brian.goetz@oracle.com>, "Tagir Valeev" <amaembo@gmail.com>, "amber-dev" <amber-dev@openjdk.org>, "amber-spec-experts" <amber-spec-experts@openjdk.org><br>
<b>Sent: </b>Wednesday, September 27, 2023 3:33:26 PM<br>
<b>Subject: </b>Re: [External] : Re: New candidate JEP: 456: Unnamed Variables and Patterns<br>
</blockquote>
</div>
<style style="display:none">
<!--
p
{margin-top:0;
margin-bottom:0}
-->
</style>
<div data-marker="__QUOTED_TEXT__">
<blockquote data-mce-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;" 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 class="x_elementToProof" data-mce-style="font-family: 'Segoe UI', 'Segoe UI ', 'Helvetica Neue', sans-serif; font-size: 11pt; color: #000000;" style="font-family:'Segoe UI','Segoe UI ','Helvetica Neue',sans-serif; font-size:11pt; color:#000000">
Hello Clement! </div>
<div class="x_elementToProof" data-mce-style="font-family: 'Segoe UI', 'Segoe UI ', 'Helvetica Neue', sans-serif; font-size: 11pt; color: #000000;" style="font-family:'Segoe UI','Segoe UI ','Helvetica Neue',sans-serif; font-size:11pt; color:#000000">
<br>
</div>
<div class="x_elementToProof x_ContentPasted0" data-mce-style="font-family: 'Segoe UI', 'Segoe UI ', 'Helvetica Neue', sans-serif; font-size: 11pt; color: #000000;" style="font-family:'Segoe UI','Segoe UI ','Helvetica Neue',sans-serif; font-size:11pt; color:#000000">
Thanks for letting us know. I recreated a stand alone reproduction of your report and indeed I get the verification error: <a href="https://bugs.openjdk.org/browse/JDK-8317048" id="LPlnk353078" target="_blank" rel="noopener" data-mce-href="https://bugs.openjdk.org/browse/JDK-8317048">https://bugs.openjdk.org/browse/JDK-8317048</a><br data-mce-bogus="1">
</div>
<div class="x_elementToProof x_ContentPasted0" data-mce-style="font-family: 'Segoe UI', 'Segoe UI ', 'Helvetica Neue', sans-serif; font-size: 11pt; color: #000000;" style="font-family:'Segoe UI','Segoe UI ','Helvetica Neue',sans-serif; font-size:11pt; color:#000000">
Looking into it.</div>
<div class="x_elementToProof x_ContentPasted0" data-mce-style="font-family: 'Segoe UI', 'Segoe UI ', 'Helvetica Neue', sans-serif; font-size: 11pt; color: #000000;" style="font-family:'Segoe UI','Segoe UI ','Helvetica Neue',sans-serif; font-size:11pt; color:#000000">
<br>
</div>
<div class="x_elementToProof x_ContentPasted0" data-mce-style="font-family: 'Segoe UI', 'Segoe UI ', 'Helvetica Neue', sans-serif; font-size: 11pt; color: #000000;" style="font-family:'Segoe UI','Segoe UI ','Helvetica Neue',sans-serif; font-size:11pt; color:#000000">
Angelos</div>
</blockquote>
<div><br>
</div>
<div>Hello Angelos,</div>
<div>you can also log another bug, it seems that javac allows "final" in front of a record pattern, something which is not allowed by the grammar (and also rightfully rejected by IntelliJ).</div>
<div><br>
</div>
<div>
<div data-mce-style="background-color: #ffffff; color: #080808;" style="background-color:#ffffff; color:#080808">
<pre data-mce-style="font-family: 'JetBrains Mono',monospace; font-size: 9.8pt;" style="font-family:'JetBrains Mono',monospace; font-size:9.8pt"><span data-mce-style="color: #0033b3;" style="color:#0033b3">record </span><span data-mce-style="color: #000000;" style="color:#000000">Foo</span>(<span data-mce-style="color: #0033b3;" style="color:#0033b3">int </span>x) {}<br><br><span data-mce-style="color: #0033b3;" style="color:#0033b3">public static void </span><span data-mce-style="color: #00627a;" style="color:#00627a">main</span>(<span data-mce-style="color: #000000;" style="color:#000000">String</span>[] <span data-mce-style="color: #000000;" style="color:#000000">args</span>) {<br> <span data-mce-style="color: #000000;" style="color:#000000">Object o </span>= <span data-mce-style="color: #000000;" style="color:#000000">args</span>;<br> <span data-mce-style="color: #0033b3;" style="color:#0033b3">switch</span>(<span data-mce-style="color: #000000;" style="color:#000000">o</span>) {<br> <span data-mce-style="color: #0033b3;" style="color:#0033b3">case final </span>Foo(<span data-mce-style="color: #0033b3;" style="color:#0033b3">int </span>x) -> {} // oops !<br> <span data-mce-style="color: #0033b3;" style="color:#0033b3">default </span>-> {}<br> }<br>}</pre>
</div>
</div>
<div><br>
</div>
<div>regards,</div>
<div>RĂ©mi</div>
<div><br>
</div>
<blockquote data-mce-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;" 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 class="x_elementToProof" data-mce-style="font-family: 'Segoe UI', 'Segoe UI ', 'Helvetica Neue', sans-serif; font-size: 11pt; color: #000000;" style="font-family:'Segoe UI','Segoe UI ','Helvetica Neue',sans-serif; font-size:11pt; color:#000000">
<br>
</div>
<div class="x_elementToProof" data-mce-style="font-family: 'Segoe UI', 'Segoe UI ', 'Helvetica Neue', sans-serif; font-size: 11pt; color: #000000;" style="font-family:'Segoe UI','Segoe UI ','Helvetica Neue',sans-serif; font-size:11pt; color:#000000">
<br>
</div>
<hr data-mce-style="display: inline-block; width: 98%;" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><span data-mce-style="font-size: 11pt; color: #000000; font-family: Calibri, sans-serif;" style="font-size:11pt; color:#000000; font-family:Calibri,sans-serif"><b>From:</b> Clément BOUDEREAU <cboudereau@gmail.com><br>
<b>Sent:</b> 27 September 2023 09:55<br>
<b>To:</b> Gavin Bierman <gavin.bierman@oracle.com><br>
<b>Cc:</b> Brian Goetz <brian.goetz@oracle.com>; Tagir Valeev <amaembo@gmail.com>; amber-dev@openjdk.org <amber-dev@openjdk.org>; Angelos Bimpoudis <angelos.bimpoudis@oracle.com>; amber-spec-experts <amber-spec-experts@openjdk.org><br>
<b>Subject:</b> [External] : Re: New candidate JEP: 456: Unnamed Variables and Patterns</span>
<div> </div>
</div>
<div>
<div dir="ltr">Hi Amber dev team,<br>
<br>
Firstly, thank you for the awesome work done.<br>
<div><br>
</div>
<div>I tried to use unnamed variable to simplifiy pattern matching in existing code with preview feature enable and JDK21 but ended up with runtime exception. The code compiles but unit test fails while I am actually running unit test with other preview feature.<br>
<br>
Here is the PR with the problem and temporary workaround : <br>
<a href="https://urldefense.com/v3/__https://github.com/cboudereau/dataseries/pull/34__;!!ACWV5N9M2RV99hQ!IQaUoSdPFw6-k9Xl8bh66a2ULWyr2pCGqHgDBldDFjJNesjswhMSNWPshaJor8k95x4FVDPHBA2WQlMKyak3HQUSGQ$" target="_blank" rel="noopener" data-mce-href="https://urldefense.com/v3/__https://github.com/cboudereau/dataseries/pull/34__;!!ACWV5N9M2RV99hQ!IQaUoSdPFw6-k9Xl8bh66a2ULWyr2pCGqHgDBldDFjJNesjswhMSNWPshaJor8k95x4FVDPHBA2WQlMKyak3HQUSGQ$">https://github.com/cboudereau/dataseries/pull/34</a><br>
</div>
<div><br>
</div>
<div>FYI, I have another pull request to integrate as soon as possible preview feature of the latest jdk21 here where everything work fine locally :<br>
<a href="https://urldefense.com/v3/__https://github.com/cboudereau/dataseries/pull/24__;!!ACWV5N9M2RV99hQ!IQaUoSdPFw6-k9Xl8bh66a2ULWyr2pCGqHgDBldDFjJNesjswhMSNWPshaJor8k95x4FVDPHBA2WQlMKyakzNtsm5g$" target="_blank" rel="noopener" data-mce-href="https://urldefense.com/v3/__https://github.com/cboudereau/dataseries/pull/24__;!!ACWV5N9M2RV99hQ!IQaUoSdPFw6-k9Xl8bh66a2ULWyr2pCGqHgDBldDFjJNesjswhMSNWPshaJor8k95x4FVDPHBA2WQlMKyakzNtsm5g$">https://github.com/cboudereau/dataseries/pull/24</a><br>
<br>
Here is the error at runtime:</div>
<div><br>
</div>
<div>[ERROR] SimpleTest.simple:17 ┬╗ Verify Bad local variable type<br>
Exception Details:<br>
Location:<br>
io/github/cboudereau/dataseries/Union$Value.compareTo(Lio/github/cboudereau/dataseries/Union$Value;)I @297: aload<br>
Reason:<br>
Type top (current frame, locals[9]) is not assignable to reference type<br>
Current Frame:<br>
bci: @297<br>
flags: { }<br>
locals: { 'io/github/cboudereau/dataseries/Union$Value', 'io/github/cboudereau/dataseries/Union$Value', '[Z', 'io/github/cboudereau/dataseries/Union$Value$Tuple', integer, 'io/github/cboudereau/dataseries/Union$Value$Tuple', top, top, top, top, top, 'io/github/cboudereau/dataseries/Union$Value$Fixed',
'io/github/cboudereau/dataseries/Union$Value', integer, 'io/github/cboudereau/dataseries/Union$Value', integer }
<br>
stack: { }<br>
Bytecode:<br>
0000000: 1278 c000 7a4d bb00 0c59 2a2b b700 0e59<br>
0000010: b800 1157 4e03 3604 2c05 0454 2d15 04ba<br>
0000020: 0017 0000 ab00 0000 0000 0014 0000 0001<br>
0000030: 0000 0000 0000 0022 bb00 1b59 0101 b700<br>
0000040: 1d2c 0604 54bf 2d3a 0519 052c 0704 54b6<br>
0000050: 0020 c000 243a 0c2c 0804 5403 360d 2c10<br>
0000060: 0604 5419 0c15 0dba 0026 0000 aa00 0000<br>
0000070: 0000 00df ffff ffff 0000 0001 0000 00df<br>
0000080: 0000 001c 0000 006d 1905 2c10 0704 54b6<br>
0000090: 0027 c000 243a 0e03 360f 190e 150f ba00<br>
00000a0: 2600 00aa 0000 002b ffff ffff 0000 0001<br>
00000b0: 0000 002b 0000 0019 0000 0022 032c 1008<br>
00000c0: 0454 a700 9404 2c10 0904 54a7 008b 0436<br>
00000d0: 0d2c 100a 0454 a7ff 8d19 052c 100b 0454<br>
00000e0: b600 27c0 0024 3a0e 2c10 0c04 5403 360f<br>
00000f0: 190e 150f ba00 2600 00aa 0000 0000 0047<br>
0000100: ffff ffff 0000 0001 0000 0047 0000 001b<br>
0000110: 0000 0024 022c 100d 0454 a700 3c19 0ec0<br>
0000120: 0001 3a0b 2c10 0e04 5419 09b4 002a 190b<br>
0000130: b400 2ab9 002e 0200 2c10 0f04 54a7 0019<br>
0000140: 0536 0d2c 1010 0454 a7ff 1b04 3604 2c10<br>
0000150: 1104 54a7 fec9 2c10 1204 54ac 4ebb 001b<br>
0000160: 592d b600 362d b700 1d2c 1013 0454 bf<br>
Exception Handler Table:<br>
bci [75, 82] => handler: 348<br>
bci [138, 146] => handler: 348<br>
bci [219, 227] => handler: 348<br>
Stackmap Table:<br>
append_frame(@28,Object[#122],Object[#12],Integer)<br>
same_frame(@56)<br>
same_frame(@70)<br>
full_frame(@99,{Object[#36],Object[#36],Object[#122],Object[#12],Integer,Object[#12],Top,Top,Top,Top,Top,Top,Object[#36],Integer},{})
<br>
same_frame(@136)<br>
append_frame(@154,Object[#36],Integer)<br>
same_frame(@188)<br>
same_frame(@197)<br>
same_frame(@206)<br>
chop_frame(@217,2)<br>
append_frame(@240,Object[#36],Integer)<br>
same_frame(@276)<br>
same_frame(@285)<br>
same_frame(@320)<br>
chop_frame(@331,2)<br>
full_frame(@342,{Object[#36],Object[#36],Object[#122]},{Integer})<br>
same_locals_1_stack_item_frame(@348,Object[#52])<br>
</div>
</div>
<br>
<div class="x_x_gmail_quote">
<div dir="ltr" class="x_x_gmail_attr">On Tue, Sep 26, 2023 at 6:14 PM Gavin Bierman <<a href="mailto:gavin.bierman@oracle.com" target="_blank" rel="noopener" data-mce-href="mailto:gavin.bierman@oracle.com">gavin.bierman@oracle.com</a>> wrote:<br>
</div>
<blockquote class="x_x_gmail_quote" data-mce-style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; padding-left: 1ex;" style="margin:0px 0px 0px 0.8ex; border-left:1px solid #cccccc; padding-left:1ex">
<div>
<div dir="auto">That’s right. We made a decision to simplify the grammar of switch labels for the JEP to only have a single pattern. However, if you use the "colon form” you can express similar code:</div>
<div dir="auto"><br>
</div>
<div dir="auto">
<div dir="auto"><span style="font-family:Monaco">gmb@gmb-mac src % cat Switch.java </span></div>
<div dir="auto"><span style="font-family:Monaco">public class Switch {</span></div>
<div dir="auto"><span style="font-family:Monaco"><br>
</span></div>
<div dir="auto"><span style="font-family:Monaco"> sealed interface X { }</span></div>
<div dir="auto"><span style="font-family:Monaco"><br>
</span></div>
<div dir="auto"><span style="font-family:Monaco"> enum E implements X {A;}</span></div>
<div dir="auto"><span style="font-family:Monaco"><br>
</span></div>
<div dir="auto"><span style="font-family:Monaco"> record R() implements X { }</span></div>
<div dir="auto"><span style="font-family:Monaco"><br>
</span></div>
<div dir="auto"><span style="font-family:Monaco"> public void work(X x) {</span></div>
<div dir="auto"><span style="font-family:Monaco"> var result = switch (x) {</span></div>
<div dir="auto"><span style="font-family:Monaco"> case E.A:</span></div>
<div dir="auto"><span style="font-family:Monaco"> case R(): yield 42;</span></div>
<div dir="auto"><span style="font-family:Monaco"> // exhaustive!</span></div>
<div dir="auto"><span style="font-family:Monaco"> };</span></div>
<div dir="auto"><span style="font-family:Monaco"> }</span></div>
<div dir="auto"><span style="font-family:Monaco"><br>
</span></div>
<div dir="auto"><span style="font-family:Monaco"> public static void main(String[] args) {</span></div>
<div dir="auto"><span style="font-family:Monaco"> System.out.println("complete");</span></div>
<div dir="auto"><span style="font-family:Monaco"> }</span></div>
<div dir="auto"><span style="font-family:Monaco">}</span></div>
<div dir="auto"><span style="font-family:Monaco">gmb@gmb-mac src % java Switch.java</span></div>
<div dir="auto"><span style="font-family:Monaco">complete</span></div>
<div><br>
</div>
</div>
<div dir="auto"><br>
</div>
<div dir="auto">As you point out, a more uniform treatment would treat all constants as patterns and allow them all to appear in pattern lists of record patterns, for example. Working on it!!</div>
<div dir="auto"><br>
</div>
<div dir="auto">Gavin<br>
<div><br>
<blockquote>
<div>On 26 Sep 2023, at 14:52, Brian Goetz <<a href="mailto:brian.goetz@oracle.com" target="_blank" rel="noopener" data-mce-href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>> wrote:</div>
<br>
<div>
<div><span style="font-size:large"><span style="font-family:monospace">I see now I answered a slightly different question :)
<br>
<br>
We do support case labels for enums in pattern switches, and they participate in exhaustiveness. But we don't currently support mixing `case pattern, constant-label` in a single case label. This is waiting for a more comprehensive treatment of constants as
patterns. <br>
</span></span><br>
<div>On 9/26/2023 8:32 AM, Tagir Valeev wrote:<br>
</div>
<blockquote>
<pre>Hello! As we are finalizing this feature, can we squeeze in a little
improvement? Namely, support enum and patterns within the same case
label, provided that the patterns do not declare any variables. Like:
enum X {A, B}
static void test(Object obj) {
switch (obj) {
case String _, X.B -> System.out.println("B or String");
default -> System.out.println("other");
}
}
public static void main(String[] args) {
Test.test("ddd");
Test.test(X.B);
}
Currently, such a code is not supported. Or will it be considered in
future JEPs?
With best regards,
Tagir Valeev.
On Mon, Sep 25, 2023 at 6:25 PM Mark Reinhold <a href="mailto:mark.reinhold@oracle.com" target="_blank" rel="noopener" data-mce-href="mailto:mark.reinhold@oracle.com"><mark.reinhold@oracle.com></a> wrote:
</pre>
<blockquote>
<pre><a href="https://openjdk.org/jeps/456" target="_blank" rel="noopener" data-mce-href="https://openjdk.org/jeps/456">https://openjdk.org/jeps/456</a>
Summary: Enhance the Java language with unnamed variables, which
can be initialized but not used, and unnamed patterns, which match a
record component without stating the component's name or type. Both are
denoted by an underscore character, _.
- Mark
</pre>
</blockquote>
</blockquote>
<br>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
<br clear="all">
<div><br>
</div>
<span class="x_x_gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="x_x_gmail_signature">C.BOUDEREAU</div>
</div>
<br>
</blockquote>
</div>
</div>
</div>
</body>
</html>