I have a trait Outer
with a member F
that is a type constructor. I want to supply type-class instances for F
, but somehow at one point the implicit resolution of scalac
stops working.
I tried to build a smaller minimal example, but I had to add everything below to make the error appear. Note how the second-to-last line still compiles, properly picking up the implicit from the nested companion object in sub
.
But the last line doesn't compile anymore. Also note that when specifying the implicit method in the second-to-last line, it compiles.
Can anyone provide a clue for why this happens?
trait TC[F[_]]
trait Outer[N[_]] {
trait F[_]
object F {
implicit val tcInst: TC[F] = new TC[F]{}
}
}
case class Sub[N[_]]() extends Outer[N]
object Test{
implicit val optionInst: TC[Option] = new TC[Option]{}
val sub = Sub[Option]()
val sub2 = Sub[sub.F]()
implicitly[TC[sub.F]] //compiles
implicitly[TC[sub2.F]](sub2.F.tcInst) //compiles
implicitly[TC[sub2.F]] //doesn't compile
}
The last line yields the following error:
Error:(22, 13) could not find implicit value for parameter e: test.novariance.TC[test.novariance.Test.sub2.F]
implicitly[TC[sub2.F]] //doesn't compile
^
Error:(22, 13) not enough arguments for method implicitly: (implicit e: test.novariance.TC[test.novariance.Test.sub2.F])test.novariance.TC[test.novariance.Test.sub2.F].
Unspecified value parameter e.
implicitly[TC[sub2.F]] //doesn't compile
^