title: Deriving circe Codec for a sealed case class family where base trait has a (sealed) type member
body: <p>I can easily generically derive a codec for a sealed case class family like this:</p>
  
  <pre><code>import io.circe._
  import io.circe.generic.auto._
  
  sealed trait Base
  case class X(x: Int) extends Base
  case class Y(y: Int) extends Base
  
  object Test extends App {
    val encoded = Encoder[Base].apply(Y(1))
    val decoded = Decoder[Base].apply(encoded.hcursor)
    println(decoded) // Right(Y(1))
  }
  </code></pre>
  
  <p>However, if I add a type member to the base class I can't do it anymore, even if it's bounded by a sealed trait:</p>
  
  <pre><code>import io.circe._
  import io.circe.generic.auto._
  
  sealed trait Inner
  case class I1(i: Int) extends Inner
  case class I2(s: String) extends Inner
  
  sealed trait Base { type T &lt;: Inner }
  case class X[S &lt;: Inner](x: S) extends Base { final type T = S }
  case class Y[S &lt;: Inner](y: S) extends Base { final type T = S }
  
  object Test extends App {
    val encodedInner = Encoder[Inner].apply(I1(1))
    val decodedInner = Decoder[Inner].apply(encodedInner.hcursor) // Ok
    println(decodedInner) // Right(I1(1))
  
    // Doesn't work: could not find implicit for Encoder[Base] etc
    // val encoded = Encoder[Base].apply(Y(I1(1)))
    // val decoded = Decoder[Base].apply(encoded.hcursor)
    // println(decoded)
  }
  </code></pre>
  
  <p>Is there a way I can achieve what I want? If not, what can I change to get something similar?</p>