<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><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>"Brian Goetz" <brian.goetz@oracle.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"amber-spec-experts" <amber-spec-experts@openjdk.java.net><br><b>Sent: </b>Thursday, April 21, 2022 6:20:24 PM<br><b>Subject: </b>Re: [External] : Re: Record pattern and side effects<br></blockquote></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;"><br>
    <blockquote cite="mid:1535408822.14991807.1650533325656.JavaMail.zimbra@u-pem.fr">
      <blockquote style="color: #007cff;">
        <pre class="moz-quote-pre">We’ve already asked one of the questions on side effects (though not sure we
agreed on the answer): what if the dtor throws?  The working story is that the
exception is wrapped in a MatchException.  (I know you don’t like this, but
let’s not rehash the same arguments.)
</pre>
      </blockquote>
      <pre class="moz-quote-pre">Wrapping exceptions into a MatchException destroy any idea of refactoring from a cascade of if ... instanceof to a switch.

I think refactoring is a use case we should support.</pre>
    </blockquote>
    <br>
    Wrapping exceptions thrown from dtors does not affect refactoring. 
    <br>
    <br>
    If I have:<br>
    <br>
        if (x instanceof D(P)) A;<br>
        else if (x instanceof D(Q)) B;<br>
        else C;<br>
    <br>
    and I refactor to <br>
    <br>
        switch (x) { <br>
            case D(P): A; break;<br>
            case D(Q): B; break;<br>
            default: C<br>
        }<br>
    <br>
    Let's imagine that dtor D throws.  The wrapping happens when a
    dtor/accessor is invoked _implicitly_ as a result of evaluating a
    pattern match.  In both cases, we will wrap the thrown exception and
    throw MatchException.  In this way, both instanceof and switch are
    "clients of" pattern matching, and it is pattern matching that
    throws.  <br>
    <br>
    I don't see any destruction here.  </blockquote><div><br></div><div>I'm thinking about the refactoring from a code using accessors to a code using a deconstructor.</div><div>By example, IDEs may propose to refactor this code<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>  if (x instanceof D d) A(d.p()); else B;<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>to<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>  if (x instanceof D(P p)) A(p); else B;</div><div><br></div><div>or vice versa </div><div>If you wraps deconstructor exceptions, but not accessor exceptions you have mismatch.<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>And as i said earlier, there is also the issue with a deconstructor calling another deconstructor (like your example with super), you may wrap a MatchException into a MatchException.</div><div><br data-mce-bogus="1"></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>