Closed
Description
minimized code
trait Has[_]
trait A
trait B
trait C
trait ZLayer[-RIn, +E, +ROut]
object ZLayer {
def fromServices[A0, A1, B](f: (A0, A1) => B): ZLayer[Has[A0] with Has[A1], Nothing, Has[B]] =
???
}
val live: ZLayer[Has[A] & Has[B], Nothing, Has[C]] =
ZLayer.fromServices { (a: A, b: B) =>
new C {}
}
Compilation output
// type mismatch
// found: (A, B) => C
// required: (A, A) => C
expectation
I would have expected this to compile because live
expected a ZLayer
with the first parameter of Has[A] with Has[B]
, which corresponds to a function (A, B) => C
like I am providing. But the compiler seems to be expecting the first part of the intersection type twice. If I change the type signature of the first parameter in the return type of fromServices
to Has[B] with Has[A]
then I get an error that the compiler expected (B, B) => C
. This issue also appears to exist on Scala 2, reported at scala/bug#11898.