I have a trait Outerwith an element Fthat is a type constructor. I want to provide instances of type type for F, but somehow at some point, the implicit permission scalacstops working.
I tried to create a smaller minimal example, but I had to add everything below to get an error. Note that the second line is still compiling, correctly picking up the implicit from the nested companion object in sub.
But the last line no longer compiles. Also note that when you specify an implicit method in the second or last line, it compiles.
Can someone make it clear why this is happening?
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 following error appears on the last line:
Error:(22, 13) could not find implicit value for parameter e: test.novariance.TC[test.novariance.Test.sub2.F]
implicitly[TC[sub2.F]]
^
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]]
^