Last active
August 26, 2022 09:02
-
-
Save imkiva/8db13b6e578e473c1c9b977086bfe898 to your computer and use it in GitHub Desktop.
Java bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment