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

Fix Coproduct case object singleton types #1152

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/shapeless/generic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ trait CaseClassMacros extends ReprTypes with CaseClassMacrosVersionSpecifics {

val ctor = if (isNamed) {
if (sym.isModuleClass) {
sym.toTypeIn(pre)
singleType(pre, sym.module)
} else {
val subst = thisType(sym).baseType(baseSym).typeArgs.map(_.typeSymbol)
val params = sym.typeParams
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/scala/shapeless/ops/coproduct.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1262,10 +1262,12 @@ object coproduct {
object LiftAll {
type Aux[F[_], In0 <: Coproduct, Out0 <: HList] = LiftAll[F, In0] {type Out = Out0}

class Curried[F[_]] {def apply[In <: Coproduct](in: In)(implicit ev: LiftAll[F, In]) = ev}
class Curried[F[_]] {
def apply[In <: Coproduct](in: In)(implicit ev: LiftAll[F, In]): Aux[F, In, ev.Out] = ev
}

def apply[F[_]] = new Curried[F]
def apply[F[_], In <: Coproduct](implicit ev: LiftAll[F, In]) = ev
def apply[F[_]]: Curried[F] = new Curried[F]
def apply[F[_], In <: Coproduct](implicit ev: LiftAll[F, In]): Aux[F, In, ev.Out] = ev

implicit def liftAllCnil[F[_]]: LiftAll.Aux[F, CNil, HNil] = new LiftAll[F, CNil] {
type Out = HNil
Expand Down
3 changes: 3 additions & 0 deletions core/src/test/scala/shapeless/generic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ class GenericTests {

val c1 = gen.from(c0)
typed[Enum](c1)

val abc = ops.coproduct.LiftAll[Witness.Aux, gen.Repr]
assertEquals(List(A, B, C), abc.instances.toList.map(_.value))
}

@Test
Expand Down