<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@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;}
/* Style Definitions */
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;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="DE" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">I can confirm this for Eclipse Adoptium 19.0.1+10 and Eclipse Adoptium 17.0.5+8 on MacOS with your code.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">I am with you that it looks strange as since JEP 394 [1] instance of Pattern is a permanent features and
</span><span lang="EN-US" style="font-family:"Courier New"">input instanceof Triple t
</span><span lang="EN-US">seems like such. But the error message points us to UnconditionalPatterns and in my case to the subtype Triple and Triple Deconstruction Patterns are in Preview with JEP 433. Is it possible that the Compiler interprets instance of
Patterns with Record Classes as Record Patterns?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Nerveless your last Question regarding why
</span><span lang="EN-US" style="font-family:"Courier New"">input instanceof Triple t</span><span lang="EN-US"> raises an error but
</span><span lang="EN-US" style="font-family:"Courier New"">input instanceof Triple</span><span lang="EN-US"> is simpler. The latter is not a Pattern, it’s a Boolean expression and is a permanent feature since the introduction of instance of.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">For the record I am not part of the Dev team, I am “only” part of the consuming community
</span><span lang="EN-US" style="font-family:"Apple Color Emoji"">😉</span><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Best Merlin<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">[1] <a href="https://openjdk.org/jeps/394">
https://openjdk.org/jeps/394</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">[2] <a href="https://openjdk.org/jeps/433">
https://openjdk.org/jeps/433</a><o:p></o:p></span></p>
<div>
<div style="border:none;border-bottom:solid windowtext 1.0pt;padding:0cm 0cm 1.0pt 0cm">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
</div>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Merlin Bögershausen<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">E: <a href="mailto:Merlin.Boegershausen@rwth-aachen.de">
<span style="color:#0563C1">Merlin.Boegershausen@rwth-aachen.de</span></a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">W: <a href="https://mboegers.github.io">
<span style="color:#0563C1">https://mboegers.github.io</span></a><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">Von: </span></b><span style="font-size:12.0pt;color:black">amber-dev <amber-dev-retn@openjdk.org> im Auftrag von David Alayachew <davidalayachew@gmail.com><br>
<b>Datum: </b>Montag, 2. Januar 2023 um 05:56<br>
<b>An: </b>amber-dev <amber-dev@openjdk.org><br>
<b>Betreff: </b>I am having trouble understanding the purpose of Unconditional Patterns<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"Courier New""><br>
Hello Amber Dev Team,<br>
<br>
I was working on some code using Pattern-Matching for instanceof, and then I ran into a surprising warning.<br>
<br>
Here is the code.<br>
<br>
public class UnconditionalPatternsPreviewWarning<br>
{<br>
<br>
public record Triple(int a, int b, int c) {}<br>
<br>
public static void main(String[] args)<br>
{<br>
<br>
System.out.println("Java Version = " + System.getProperty("java.version"));<br>
<br>
final Triple input = new Triple(1, 2, 3);<br>
<br>
if (input instanceof Triple t)<br>
{<br>
<br>
System.out.println("Made it here");<br>
<br>
}<br>
<br>
}<br>
<br>
}<br>
<br>
And here is the warning.<br>
<br>
$ javac -Xlint:preview --enable-preview --release 19 UnconditionalPatternsPreviewWarning.java<br>
UnconditionalPatternsPreviewWarning.java:15: warning: [preview] unconditional patterns in instanceof are a preview feature and may be removed in a future release.<br>
if (input instanceof Triple t)<br>
^<br>
1 warning<br>
<br>
I tried searching for what this warning means, but couldn't find it. More specifically, I couldn't understand what Unconditional Patterns meant. With some help from StackOverflow (<a href="https://stackoverflow.com/questions/74978665">https://stackoverflow.com/questions/74978665</a>),
I was led to a blog by Nicolai Parlog, which explained the meaning.<br>
<br>
> ...an unconditional pattern, that is, a <br>
> pattern that matches all possible<br>
> instances of the switched variable’s type.<br>
<br>
I understand the meaning well enough. Basically, it is saying that the compiler knows 100% that a variable is fully and unconditionally matched by the given pattern. Therefore, it is considered an unconditional pattern. As a result, since unconditional patterns
are in preview (while instanceof pattern-matching has since been released as General Availability), then I now understand my warning and why it occurred.<br>
<br>
But that leads to a couple questions.<br>
<br>
The fact that you all made this delineation meant that it is something worth denoting. Why? What about it is so significant that you would denote this? In fact, if I turn off the --enable-preview features flag and the Xlint check, that warning turns into an
error for the exact same reason -- my pattern fully encompasses all possible values of my variable. So this is clearly something that needed a big fence put around it.<br>
<br>
Is there some (upcoming) functionality involving pattern-matching that depends on this delineation?
<br>
<br>
Why make this delineation for the following snippet, but not the one below it?<br>
<br>
if (input instanceof Triple t) {} //error or warning, depending on what you compile with<br>
<br>
if (input instanceof Triple) {} //compiles fine and runs fine<br>
<br>
Is it because of backwards compatibility?<br>
<br>
Thank you all for your time and your help!<br>
David Alayachew<o:p></o:p></span></p>
</div>
</div>
</div>
</body>
</html>