Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot derive generic for sealed trait family if base trait has a type member, even if bounded by another sealed trait #585

Open
TrustNoOne opened this issue Apr 27, 2016 · 0 comments

Comments

@TrustNoOne
Copy link

I can get a generic representation of my Base[T] if Base is sealed and T is bounded by another sealed trait:

  sealed trait Inner
  case class I1(i: Int) extends Inner
  case class I2(s: String) extends Inner

  sealed trait Base[T <: Inner]
  case class X[I <: Inner](x: I) extends Base[I]
  case class Y[I <: Inner](y: I) extends Base[I]

  Generic[Inner] // ok
  Generic[Base[_ <: Inner]] //ok

However, if T is a type member, I can't do it anymore:

  sealed trait Inner
  case class I1(i: Int) extends Inner
  case class I2(s: String) extends Inner

  sealed trait Base { type T <: Inner }
  object Base { type Aux[S <: Inner] = Base { type T = S } }
  case class X[S <: Inner](x: S) extends Base { final type T = S }
  case class Y[S <: Inner](y: S) extends Base { final type T = S }

  Generic[Base] // doesn't work
  Generic[Base { type T <: Inner }] // doesn't work
  Generic[Base.Aux[_ <: Inner]] // doesn't work

@milessabin already suggested in gitter that even if in theory this could be possible, the compiler doesn't allow it at the moment: in principle the match on the S values and the equation between S and T could be used to refine T, but the Scala compiler doesn't do that at the moment.

@milessabin milessabin added this to the shapeless-2.4.0 milestone Aug 18, 2016
@joroKr21 joroKr21 modified the milestones: shapeless-2.4.0, shapeless-2.5.0 Mar 20, 2020
@joroKr21 joroKr21 removed this from the shapeless-2.5.0 milestone Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants