<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>"Gavin Bierman" <gavin.bierman@oracle.com>, "Manoj Palat" <manoj.palat@in.ibm.com>, "amber-spec-experts" <amber-spec-experts@openjdk.java.net><br><b>Sent: </b>Lundi 19 Juillet 2021 15:49:22<br><b>Subject: </b>Re: [External] : Re: case null and type pattern<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;" 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;"><span style="font-size: xx-small;"><span style="font-family: monospace;">Sure, but again, I think users would find that restriction even more annoying; the vast majority of guards in languages with guarded patterns use the bindings to refine the match.  I'm not sure users would thank us for moving the restriction in this way.</span></span></blockquote><div><br></div><div>I was thinking about the binding after the ':' or '->', not the fact that the same binding is used inside a guard,</div><div>because it's not exactly the same binding.</div><div><br></div><div>Let's compare</div><div>   case String s && s != null -></div><div>and<br data-mce-bogus="1"></div><div>   case null, String s && s != null -></div><div><br></div><div>in the second case, there is a 'merge' between null and String s, there are two questions, do we allow this kind of merge and does a merge with null a special kind of merge.<br></div><div><br></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;" 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;"><span style="font-size: xx-small;"><span style="font-family: monospace;"><br>A more interesting flavor of the same question, though, is what happens if we allow _ to be used as a binding name.  Then, the restriction on fall-through could be relaxed if we wanted; it would be safe to do:<br><br>    case Foo _, Bar _: blah<br><br>whereas today we don't allow mixing of these patterns.  </span></span></blockquote><div><br></div><div>I agree, it seems we want to allow some merging (with null, with '_', are there others ??) but not the general form.<br></div><div><br data-mce-bogus="1"></div><div>Rémi<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;" 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;"><br><div class="moz-cite-prefix">On 7/19/2021 9:09 AM, Remi Forax wrote:<br></div><blockquote cite="mid:2071220884.417222.1626700191999.JavaMail.zimbra@u-pem.fr"><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000;" data-mce-style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000;"><div><br></div><div><br></div><hr id="zwchr"><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;" 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;"><b>From: </b>"Brian Goetz" <a class="moz-txt-link-rfc2396E" href="mailto:brian.goetz@oracle.com" target="_blank" rel="noopener" data-mce-href="mailto:brian.goetz@oracle.com"><brian.goetz@oracle.com></a><br><b>To: </b>"Gavin Bierman" <a class="moz-txt-link-rfc2396E" href="mailto:gavin.bierman@oracle.com" target="_blank" rel="noopener" data-mce-href="mailto:gavin.bierman@oracle.com"><gavin.bierman@oracle.com></a>, "Manoj Palat" <a class="moz-txt-link-rfc2396E" href="mailto:manoj.palat@in.ibm.com" target="_blank" rel="noopener" data-mce-href="mailto:manoj.palat@in.ibm.com"><manoj.palat@in.ibm.com></a><br><b>Cc: </b>"amber-spec-experts" <a class="moz-txt-link-rfc2396E" href="mailto:amber-spec-experts@openjdk.java.net" target="_blank" rel="noopener" data-mce-href="mailto:amber-spec-experts@openjdk.java.net"><amber-spec-experts@openjdk.java.net></a><br><b>Sent: </b>Lundi 19 Juillet 2021 15:00:16<br><b>Subject: </b>Re: case null and type pattern<br></blockquote></div><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;" 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;"><span style="font-size: xx-small;"><span style="font-family: monospace;">Right.  In theory, we could allow guarded patterns here, but they will be hard to use, since users will likely want to use the binding in the guard, and would have to check for nullity every time.  </span></span></blockquote><div><br></div><div>As you said, the error is to be able to use the binding not to be able to express that pattern.<br></div><div><br></div><div>Rémi<br></div><div><br></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;" 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;"><br><br><div class="moz-cite-prefix">On 7/19/2021 6:16 AM, Gavin Bierman wrote:<br></div><blockquote cite="mid:8E0D6D09-E4E6-4D7C-AC2D-CBE71727BD50@oracle.com"><pre class="moz-quote-pre">Hi Manoj,

This is certainly something we can discuss for Preview 2, but…it is intentional for now. The `case null, T t` is really a special case of extending a type pattern to be null friendly. Remember that the pattern variable `t` is initialised with null if this case label applies. 

The problem with what you are suggesting is that we’re going to end up with code like:

switch(o) {
    â€¦
    case null, String s && s != null -> â€¦
}

Now the developer has a guard saying that `s` is not null, and is probably going to assume this in the body of the switch rule, but has erroneously extended the case label with null. 

So, it’s just an attempt to remove potential puzzlers by design. But we can take a look at whether we can capture a more generous definition. An alternative would be to define a new null-friendly type pattern. Let’s talk about it!

Thanks,
Gavin



</pre><blockquote><pre class="moz-quote-pre">On 14 Jul 2021, at 23:43, Manoj Palat <a class="moz-txt-link-rfc2396E" href="mailto:manoj.palat@in.ibm.com" target="_blank" rel="noopener" data-mce-href="mailto:manoj.palat@in.ibm.com"><manoj.palat@in.ibm.com></a> wrote:

Hi Gavin, All,

In <a class="moz-txt-link-freetext" href="http://cr.openjdk.java.net/~gbierman/jep406/jep406-20210608/specs/patterns-switch-jls.html#jls-14.30.1" target="_blank" rel="noopener" data-mce-href="http://cr.openjdk.java.net/~gbierman/jep406/jep406-20210608/specs/patterns-switch-jls.html#jls-14.30.1">http://cr.openjdk.java.net/~gbierman/jep406/jep406-20210608/specs/patterns-switch-jls.html#jls-14.30.1</a>, Section 14.11, I see "If a switch label has a null case label element then if the switch label also has any pattern case element labels, they must be type patterns (14.30.1)." implying that the following code:

private static void foo(Object o) {
switch (o) {
case null, Integer i && i > 10 -> System.out.println(0); // flag error?
default -> System.out.println(o);
}
should have an error flagged for case label with null since the pattern case label element is not a type pattern but a guarded pattern.
Any reason for excluding guarded patterns here? Or does this requires a modification in spec to include guarded patterns as well?

Regards,
Manoj
</pre></blockquote></blockquote><br><br></blockquote></div></div></blockquote><br><br></blockquote></div></div></body></html>