<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div>Thanks, this is clearly a bug.<br></div><div><br data-mce-bogus="1"></div><div>The second call infer T as the intersection type Record & Term, which is erased to Record.</div><div><span lang="EN-US">Term.Lam::new is translated to an invokedynamic </span></div><div><span lang="EN-US"> Method arguments:<br> #49 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;<br> #50 REF_newInvokeSpecial Bug$Term$Lam."<init>":(Ljava/lang/String;LBug$Term;)V<br> #56 (Ljava/lang/String;Ljava/lang/Record;)Ljava/lang/Record;<br><br data-mce-bogus="1"></span></div><div><span lang="EN-US">This is a case where the compiler should desugar the method reference to a lambda with an upcast from Record to Term </span></div><div><span lang="EN-US"> <span style="font-style: italic;" data-mce-style="font-style: italic;">call</span>((String x, Record t) -> <span style="color: #000080; font-weight: bold;" data-mce-style="color: #000080; font-weight: bold;">new </span>Lam(x, (Term) t), <span style="color: #008000; font-weight: bold;" data-mce-style="color: #008000; font-weight: bold;">"x"</span>, <span style="color: #000080; font-weight: bold;" data-mce-style="color: #000080; font-weight: bold;">new </span>Term.Lit()); <br data-mce-bogus="1"></span></div><div><span lang="EN-US"><br data-mce-bogus="1"></span></div><div><span lang="EN-US">but tries to directly reference the constructor thus fails at runtime because the upcast is missing.</span></div><div><span lang="EN-US"><br data-mce-bogus="1"></span></div><div><span lang="EN-US">regards,<br data-mce-bogus="1"></span></div><div><span lang="EN-US">RĂ©mi<br data-mce-bogus="1"></span></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>"Kiva" <imkiva@islovely.icu><br><b>To: </b>"compiler-dev" <compiler-dev@openjdk.org><br><b>Sent: </b>Friday, August 26, 2022 11:04:19 AM<br><b>Subject: </b>Possible compiler bug causing LambdaConversionException<br></blockquote></div><div><style><!--
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:DengXian;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
{page:WordSection1;}
--></style></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 class="WordSection1"><p class="MsoNormal"><span lang="EN-US">Hi all,</span></p><p class="MsoNormal"><span lang="EN-US"> </span></p><p class="MsoNormal"><span lang="EN-US">I am not sure whether this should be reported to amber-dev or compiler-dev so I am reporting it here (sorry!)</span></p><p class="MsoNormal"><span lang="EN-US">A minimal repro was attached below or you can visit here: https://gist.github.com/imkiva/8db13b6e578e473c1c9b977086bfe898</span></p><p class="MsoNormal"><span lang="EN-US"> </span></p><p class="MsoNormal"><span lang="EN-US">import java.util.function.BiFunction;</span></p><p class="MsoNormal"><span lang="EN-US"> </span></p><p class="MsoNormal"><span lang="EN-US">public class Bug {</span></p><p class="MsoNormal"><span lang="EN-US"> sealed interface Term {</span></p><p class="MsoNormal"><span lang="EN-US"> record Lit() implements Term {}</span></p><p class="MsoNormal"><span lang="EN-US"> record Lam(String x, Term a) implements Term {}</span></p><p class="MsoNormal"><span lang="EN-US"> }</span></p><p class="MsoNormal"><span lang="EN-US"> </span></p><p class="MsoNormal"><span lang="EN-US"> public static <X, T> void call(BiFunction<X, T, T> op, X x, T t) {</span></p><p class="MsoNormal"><span lang="EN-US"> op.apply(x, t);</span></p><p class="MsoNormal"><span lang="EN-US"> }</span></p><p class="MsoNormal"><span lang="EN-US"> </span></p><p class="MsoNormal"><span lang="EN-US"> public static void main(String[] args) {</span></p><p class="MsoNormal"><span lang="EN-US"> // this code works</span></p><p class="MsoNormal"><span lang="EN-US"> call(Term.Lam::new, "x", (Term) new Term.Lit());</span></p><p class="MsoNormal"><span lang="EN-US"> </span></p><p class="MsoNormal"><span lang="EN-US"> // this does not</span></p><p class="MsoNormal"><span lang="EN-US"> call(Term.Lam::new, "x", new Term.Lit());</span></p><p class="MsoNormal"><span lang="EN-US"> // java.lang.invoke.LambdaConversionException: Type mismatch for lambda argument 1: </span></p><p class="MsoNormal"><span lang="EN-US"> // class java.lang.Record is not convertible to interface Term</span></p><p class="MsoNormal"><span lang="EN-US"> }</span></p><p class="MsoNormal"><span lang="EN-US">}</span></p><p class="MsoNormal"><span lang="EN-US"> </span></p></div><br></blockquote></div></div></body></html>