<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">
Hello Clement! </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">
<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">
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">https://bugs.openjdk.org/browse/JDK-8317048</a></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">
Looking into it.</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">
Angelos</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">
<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">
<br>
</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> 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</font>
<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$">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$">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_gmail_quote">
<div dir="ltr" class="x_gmail_attr">On Tue, Sep 26, 2023 at 6:14 PM Gavin Bierman <<a href="mailto:gavin.bierman@oracle.com">gavin.bierman@oracle.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); 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"><font face="Monaco">gmb@gmb-mac src % cat Switch.java </font></div>
<div dir="auto"><font face="Monaco">public class Switch {</font></div>
<div dir="auto"><font face="Monaco"><br>
</font></div>
<div dir="auto"><font face="Monaco">    sealed interface X { }</font></div>
<div dir="auto"><font face="Monaco"><br>
</font></div>
<div dir="auto"><font face="Monaco">    enum E implements X {A;}</font></div>
<div dir="auto"><font face="Monaco"><br>
</font></div>
<div dir="auto"><font face="Monaco">    record R() implements X { }</font></div>
<div dir="auto"><font face="Monaco"><br>
</font></div>
<div dir="auto"><font face="Monaco">    public void work(X x) {</font></div>
<div dir="auto"><font face="Monaco">        var result = switch (x) {</font></div>
<div dir="auto"><font face="Monaco">            case E.A:</font></div>
<div dir="auto"><font face="Monaco">            case R(): yield 42;</font></div>
<div dir="auto"><font face="Monaco">                // exhaustive!</font></div>
<div dir="auto"><font face="Monaco">        };</font></div>
<div dir="auto"><font face="Monaco">    }</font></div>
<div dir="auto"><font face="Monaco"><br>
</font></div>
<div dir="auto"><font face="Monaco">    public static void main(String[] args) {</font></div>
<div dir="auto"><font face="Monaco">        System.out.println("complete");</font></div>
<div dir="auto"><font face="Monaco">    }</font></div>
<div dir="auto"><font face="Monaco">}</font></div>
<div dir="auto"><font face="Monaco">gmb@gmb-mac src % java Switch.java</font></div>
<div dir="auto"><font face="Monaco">complete</font></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 type="cite">
<div>On 26 Sep 2023, at 14:52, Brian Goetz <<a href="mailto:brian.goetz@oracle.com" target="_blank">brian.goetz@oracle.com</a>> wrote:</div>
<br>
<div>
<div><font size="4"><font face="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>
</font></font><br>
<div>On 9/26/2023 8:32 AM, Tagir Valeev wrote:<br>
</div>
<blockquote type="cite">
<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"><mark.reinhold@oracle.com></a> wrote:
</pre>
<blockquote type="cite">
<pre><a href="https://openjdk.org/jeps/456" target="_blank">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_gmail_signature_prefix">-- </span><br>
<div dir="ltr" class="x_gmail_signature">C.BOUDEREAU</div>
</div>
</body>
</html>