<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Despite what I said in my last mail, the first <font
        face="Courier New, Courier, monospace">switch</font> that I
      showed augmented with a <font face="Courier New, Courier,
        monospace">default</font> <font face="Courier New, Courier,
        monospace">case</font> seems to execute the <font face="Courier
        New, Courier, monospace">Some<String></font> case
      anyway—which produces a <font face="Courier New, Courier,
        monospace">ClassCastException</font>—so the <font face="Courier
        New, Courier, monospace">default</font> <font face="Courier
        New, Courier, monospace">case</font> seems to be redundant
      during runtime albeit required during compilation.<br>
    </p>
    <p><font face="Courier New, Courier, monospace">   
        Option<String> option = new Some(new Object());<br>
            switch (option) {<br>
                case Some<String>(var value) ->
        System.out.println(value);<br>
                case None<String>() ->
        System.out.println("none");<br>
                case default -> System.out.println(option);<br>
            }</font></p>
    <p> So I agree with you: there seems to be a bug.<br>
    </p>
    <blockquote type="cite"
      cite="mid:3a6998f1-5985-6efa-4dc2-98c585fb0bde@gmail.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <p>I see. I apologize for my ignorant comment. After some
        experimentation, I've discovered that the <font face="Courier
          New, Courier, monospace">switch</font> compiles when the
        component of <font face="Courier New, Courier, monospace">Some</font>
        (<font face="Courier New, Courier, monospace">value</font>) is
        destructured with the type <font face="Courier New, Courier,
          monospace">Object</font> instead of <font face="Courier New,
          Courier, monospace">String</font>. Since we currently don't
        have generic reification, any <font face="Courier New, Courier,
          monospace">Option<String></font> can be cast to <font
          face="Courier New, Courier, monospace">Option<Object></font>
        successfully at runtime (<font face="Courier New, Courier,
          monospace">(Option<Object>) (Object) optionString</font>);
        which means that the error that you have shown is probably for
        preventing cases like the one below.</p>
      <p><font face="Courier New, Courier, monospace">   
          Option<String> option = new Some(new Object());<br>
              switch (option) {<br>
                  case Some<String>(var value) ->
          System.out.println(value);<br>
                  case None<String>() ->
          System.out.println("none");<br>
              }<br>
        </font></p>
      <p>Additionally, the compiler seems to deem the following code
        snippet valid.</p>
      <p><font face="Courier New, Courier, monospace">   
          Option<String> option = new Some("some");<br>
              switch (option) {<br>
                  case Some<?>(var value) ->
          System.out.println(value);<br>
                  case None<String>() ->
          System.out.println("none");<br>
              }</font></p>
      <p>The interesting thing about it is that the type argument in the
        case of <font face="Courier New, Courier, monospace">None</font>
        appears to be insignificant to the compiler so long as it's
        assignable to <font face="Courier New, Courier, monospace">String</font>.<br>
      </p>
      <blockquote type="cite"
        cite="mid:38C1A33E-9DA5-4794-A807-E6D9371AA973@hxcore.ol">
        <meta http-equiv="Content-Type" content="text/html;
          charset=UTF-8">
        <meta name="Generator" content="Microsoft Word 15 (filtered
          medium)">
        <style>@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}.MsoChpDefault
        {mso-style-type:export-only;}div.WordSection1
        {page:WordSection1;}</style>
        <div class="WordSection1">
          <p class="MsoNormal">Hello sir,</p>
          <p class="MsoNormal"><o:p> </o:p></p>
          <p class="MsoNormal">Thank you for your attention.</p>
          <p class="MsoNormal"><o:p> </o:p></p>
          <p class="MsoNormal">As I recall, « switch » without explicit
            null cases do not accept nulls.</p>
          <p class="MsoNormal"><o:p> </o:p></p>
          <p class="MsoNormal">I enriched the failing cases here and
            included commands ran and their output : <a
              href="https://gist.github.com/grimly/1cc1228feacb51eaef59bfea86d2add5"
              moz-do-not-send="true" class="moz-txt-link-freetext">https://gist.github.com/grimly/1cc1228feacb51eaef59bfea86d2add5</a></p>
          <p class="MsoNormal"><o:p> </o:p></p>
          <p class="MsoNormal">In the gist above, the « TestFailing »
            file throws as I would expect by the missing null case.</p>
          <p class="MsoNormal">Adding the null case in « TestFailing2 »
            didn’t help either.</p>
          <p class="MsoNormal"><o:p> </o:p></p>
          <p class="MsoNormal">Best regards,</p>
          <p class="MsoNormal">Michel</p>
          <p class="MsoNormal"><o:p> </o:p></p>
          <div
            style="mso-element:para-border-div;border:none;border-top:solid
            #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
            <p class="MsoNormal" style="border:none;padding:0cm"><b>From:
              </b><a href="mailto:tjmnkrajyej@gmail.com"
                moz-do-not-send="true" class="moz-txt-link-freetext">tjmnkrajyej@gmail.com</a><br>
              <b>Sent: </b>vendredi 23 septembre 2022 17:55<br>
              <b>To: </b><a href="mailto:michel.turpin1@gmail.com"
                moz-do-not-send="true">Michel Turpin</a>; <a
                href="mailto:amber-dev@openjdk.org"
                moz-do-not-send="true" class="moz-txt-link-freetext">amber-dev@openjdk.org</a><br>
              <b>Subject: </b>Bad exhaustive test using Record Pattern
              as delivered in OpenJDK 19 preview</p>
          </div>
          <p class="MsoNormal"><o:p> </o:p></p>
          <p class="MsoNormal">`opt` can be `null`.<br>
            <br>
            <o:p></o:p></p>
          <blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
            <div>
              <p class="MsoNormal">Hello, <o:p></o:p></p>
              <div>
                <p class="MsoNormal"><o:p> </o:p></p>
              </div>
              <div>
                <p class="MsoNormal">First, please excuse me for the way
                  I send this bug report. I cannot find a way to report
                  it in other ways.<o:p></o:p></p>
              </div>
              <div>
                <p class="MsoNormal"><o:p> </o:p></p>
              </div>
              <div>
                <p class="MsoNormal">Looking at the description of JEP
                  405, it made me think of Rust enums and pattern
                  matching.<o:p></o:p></p>
              </div>
              <div>
                <p class="MsoNormal">I tried then to play on how to
                  write a copy of the Rust "Option" enum : <a
                    href="https://gist.github.com/grimly/55d414f0cc3395e87a7c813176c50ac9"
                    moz-do-not-send="true" class="moz-txt-link-freetext">https://gist.github.com/grimly/55d414f0cc3395e87a7c813176c50ac9</a><o:p></o:p></p>
              </div>
              <div>
                <p class="MsoNormal"><o:p> </o:p></p>
              </div>
              <div>
                <p class="MsoNormal">But then I encountered this issue
                  when narrowing the types I use and in this particular
                  instance ( <a
href="https://gist.github.com/grimly/55d414f0cc3395e87a7c813176c50ac9#file-testfailing-java-L9-L12"
                    moz-do-not-send="true" class="moz-txt-link-freetext">https://gist.github.com/grimly/55d414f0cc3395e87a7c813176c50ac9#file-testfailing-java-L9-L12</a>
                  ), the compiler throws an error and reports the switch
                  is not exhaustive.<o:p></o:p></p>
              </div>
              <div>
                <p class="MsoNormal"><o:p> </o:p></p>
              </div>
              <div>
                <p class="MsoNormal">Given in my code "Option" is sealed
                  and may only be "Some" or "None", I would expect
                  listing both options to make my cases exhaustive.<o:p></o:p></p>
              </div>
              <div>
                <p class="MsoNormal">Adding a default case, I also fail
                  to produce an instance that would trigger it.<o:p></o:p></p>
              </div>
              <div>
                <p class="MsoNormal"><o:p> </o:p></p>
              </div>
              <div>
                <p class="MsoNormal">Best regards,<o:p></o:p></p>
              </div>
              <div>
                <p class="MsoNormal">Michel<o:p></o:p></p>
              </div>
              <div>
                <p class="MsoNormal"><br>
                  -- <o:p></o:p></p>
              </div>
            </div>
          </blockquote>
          <p
style="mso-margin-top-alt:5.0pt;margin-right:36.0pt;margin-bottom:5.0pt;margin-left:36.0pt"><span
              style="color:#1F497D">Michel TURPIN</span></p>
          <p class="MsoNormal"><o:p> </o:p></p>
        </div>
      </blockquote>
    </blockquote>
  </body>
</html>