Skip to content

AbstractMethodError when SAM-converting to trait that extends type alias of Function1 #24826

@WojciechMazur

Description

@WojciechMazur

Based on the OpenCB failure in http4s/http4s-otel4s-middleware - build logs

Compiler version

3.8.0-RC4

Last good release: 3.8.0-RC1-bin-20250817-8c3f1a6-NIGHTLY
First bad release: 3.8.0-RC1-bin-20250818-aaa39c5-NIGHTLY
Most likely issue was present in all Scala 3 versions, activated after switching stdlib to be Scala 3 compiled

Minimized code

trait Client[F[_]]
type Middleware[F[_]] = Client[F] => Client[F]

trait ClientMiddleware[F[_]] extends Middleware[F] {
  def wrapClient(client: Client[F]): Client[F]
  final def apply(client: Client[F]): Client[F] = wrapClient(client)
  final def wrapMiddleware(that: Middleware[F]): ClientMiddleware[F] =
    (client: Client[F]) => wrapClient(that(client))
}

@main def Test = {
  trait IO[T]
  def middleware: ClientMiddleware[IO] = (client: Client[IO]) => client
  middleware.wrapMiddleware(middleware).wrapClient(new Client[IO] {})
}

Output

Exception in thread "main" java.lang.AbstractMethodError: Receiver class test$package$$$Lambda$1/0x0000007001001410 does not define or inherit an implementation of the resolved method 'abstract java.lang.Object apply(java.lang.Object)' of interface scala.Function1.
        at ClientMiddleware.wrapMiddleware$$anonfun$1(test.scala:8)
        at test$package$.Test(test.scala:14)
        at Test.main(test.scala:11)

Expectation

The missing bridge should be provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugregressionThis worked in a previous version but doesn't anymorestat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions