Skip to content

Lambda syntax for SAM crashes with AbstractMethodError #10068

Closed
@sideeffffect

Description

@sideeffffect

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)

https://app.circleci.com/pipelines/github/zio/zio-prelude/741/workflows/53a57041-ca7f-442c-bd00-64fdf7c8a139/jobs/4226/steps

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions