Possible compiler bug causing LambdaConversionException
Remi Forax
forax at univ-mlv.fr
Fri Aug 26 09:52:56 UTC 2022
Thanks, this is clearly a bug.
The second call infer T as the intersection type Record & Term, which is erased to Record.
Term.Lam::new is translated to an invokedynamic
Method arguments:
#49 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
#50 REF_newInvokeSpecial Bug$Term$Lam."<init>":(Ljava/lang/String;LBug$Term;)V
#56 (Ljava/lang/String;Ljava/lang/Record;)Ljava/lang/Record;
This is a case where the compiler should desugar the method reference to a lambda with an upcast from Record to Term
call ((String x, Record t) -> new Lam(x, (Term) t), "x" , new Term.Lit());
but tries to directly reference the constructor thus fails at runtime because the upcast is missing.
regards,
Rémi
> From: "Kiva" <imkiva at islovely.icu>
> To: "compiler-dev" <compiler-dev at openjdk.org>
> Sent: Friday, August 26, 2022 11:04:19 AM
> Subject: Possible compiler bug causing LambdaConversionException
> Hi all,
> I am not sure whether this should be reported to amber-dev or compiler-dev so I
> am reporting it here (sorry!)
> A minimal repro was attached below or you can visit here:
> https://gist.github.com/imkiva/8db13b6e578e473c1c9b977086bfe898
> import java.util.function.BiFunction;
> public class Bug {
> sealed interface Term {
> record Lit() implements Term {}
> record Lam(String x, Term a) implements Term {}
> }
> public static <X, T> void call(BiFunction<X, T, T> op, X x, T t) {
> op.apply(x, t);
> }
> public static void main(String[] args) {
> // this code works
> call(Term.Lam::new, "x", (Term) new Term.Lit());
> // this does not
> call(Term.Lam::new, "x", new Term.Lit());
> // java.lang.invoke.LambdaConversionException: Type mismatch for lambda argument
> 1:
> // class java.lang.Record is not convertible to interface Term
> }
> }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20220826/a922f3d8/attachment.htm>
More information about the compiler-dev
mailing list