Closed
Description
When using the Lambda syntax for SAM type, a trait in this case, the Dotty-compiled program crashes at runtime with java.lang.AbstractMethodError
Minimized code
def make[A](ord: (A, A) => Ordering): Ord[A] =
(l, r) => ord(l, r)
Output
Dotty compiles the code without a complaint, but the code crashes at runtime.
[info] java.lang.AbstractMethodError: Method zio/prelude/Ord$$$Lambda$10282.checkCompare(Ljava/lang/Object;Ljava/lang/Object;)Lzio/prelude/PartialOrdering; is abstract
[info] at zio.prelude.Ord$$$Lambda$10282/1407254277.checkCompare(Unknown Source)
[info] at zio.prelude.PartialOrd.compare(PartialOrd.scala:21)
Expectation
Code should either fail to compile, or not crash. The same code works OK with Scala 2.
Workaround
Use the verbose way:
def make[A](ord: (A, A) => Ordering): Ord[A] = new Ord[A] {
override protected def checkCompare(l: A, r: A): Ordering = ord(l, r)
}
zio/zio-prelude@c0450bb
Then everything works as expected.