<html><body><div id="zimbraEditorContainer" style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000" class="45"><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>"Dan Heidinga" <heidinga@redhat.com><br><b>To: </b>"Remi Forax" <forax@univ-mlv.fr><br><b>Cc: </b>"John Rose" <john.r.rose@oracle.com>, "Brian Goetz" <brian.goetz@oracle.com>, "amber-spec-experts" <amber-spec-experts@openjdk.java.net><br><b>Sent: </b>Tuesday, September 13, 2022 8:42:23 PM<br><b>Subject: </b>Re: Knocking off two more vestiges of legacy switch<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;"><div dir="ltr"><div><snip></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div id="m_1608123405137719774zimbraEditorContainer" style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div><br><div>So my main concern stay that<br></div><div> String s = ...<br></div><div> switch(s) {<br></div><div> case Comparable<?> c -> ... //Dan: matches here as String implements Comparable (this case is total on "s" so no further matching)<br></div><div> case Object o -> ...<br></div><div> }<br></div><br><div>and<br></div><div> long l = ...<br></div><div> switch(l) {<br></div><div> case float f -> ... //Dan: matches here if l is convertable to a float<br></div><div> case double d -> ... //Dan: otherwise matches here<br></div><div> }<br></div><br><div>behave differently.<br></div><br></div></div></div></blockquote><br><div>In each case, we're finding the switch case that the value is compatible with. Another way to say it is the value is convertable to... or castable to. Can you expand on what you mean by "behave differently"?</div></div></div></blockquote><div><br></div><div>In the first example, both type patterns are total so it does not compile because both patterns will match all Strings.<br data-mce-bogus="1"></div><div>In the second example, if we follow the semantics proposed by Brian, the first pattern is partial and is equivalent to iff (l == (long) (float) l) { float f = l; ... } and the second pattern is total.<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 dir="ltr"><div class="gmail_quote"><br><div>I'm still working on reading through the "big picture" presentation in [0] so if there's a particular section there that you think is relevant, I can re-read that first. It might be useful for both of us to re-read it and see how this example fits with the bigger picture being proposed for pattern matching.</div></div></div></blockquote><div><br></div><div>This document give you a nice overview of the problems but some parts are outdated, the following spec correspond to the semantics for Java 19<br data-mce-bogus="1"></div><div>https://cr.openjdk.java.net/~gbierman/jep427+405/jep427+405-20220601/specs/patterns-switch-record-patterns-jls.html#jls-15.28<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>The proposed semantics of the primitive pattern is described here<br data-mce-bogus="1"></div><div> https://mail.openjdk.org/pipermail/amber-spec-experts/2022-September/003497.html</div><div>and here<br data-mce-bogus="1"></div><div> https://mail.openjdk.org/pipermail/amber-spec-experts/2022-September/003499.html</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 dir="ltr"><div class="gmail_quote"><br><div>--Dan</div><br><div>[0] <a href="https://openjdk.org/projects/amber/design-notes/patterns/pattern-match-object-model" target="_blank">https://openjdk.org/projects/amber/design-notes/patterns/pattern-match-object-model</a><br data-mce-bogus="1"></div></div></div></blockquote><div><br></div><div>Rémi<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div></div></div></body></html>