Permalink
Browse files

Reduce implicit priority of `materializeCoproduct`

  • Loading branch information...
jvican committed May 29, 2018
1 parent a3113b3 commit 9a6d70cbda92849ff2a9b3d99f2aa4d5d82bf21f
Showing with 17 additions and 15 deletions.
  1. +17 −15 core/src/main/scala/shapeless/generic.scala
@@ -202,7 +202,23 @@ trait LabelledGeneric[T] extends Serializable {
def from(r : Repr) : T
}

object LabelledGeneric {
trait CoproductLabelledGeneric {
/** Handles the Coproduct case (specifying subclasses derive from a sealed trait) */
implicit def materializeCoproduct[T, K <: HList, V <: Coproduct, R <: Coproduct]
(implicit
lab: DefaultSymbolicLabelling.Aux[T, K],
gen: Generic.Aux[T, V],
zip: coproduct.ZipWithKeys.Aux[K, V, R],
ev: R <:< V
): LabelledGeneric.Aux[T, R] =
new LabelledGeneric[T] {
type Repr = R
def to(t: T): Repr = zip(gen.to(t))
def from(r: Repr): T = gen.from(r)
}
}

object LabelledGeneric extends CoproductLabelledGeneric {

/** Like [[shapeless.Generic.Aux]], this is an implementation of the Aux pattern, please
* see comments there.
@@ -228,20 +244,6 @@ object LabelledGeneric {
def to(t: T): Repr = zip(gen.to(t))
def from(r: Repr): T = gen.from(r)
}

/** Handles the Coproduct case (specifying subclasses derive from a sealed trait) */
implicit def materializeCoproduct[T, K <: HList, V <: Coproduct, R <: Coproduct]
(implicit
lab: DefaultSymbolicLabelling.Aux[T, K],
gen: Generic.Aux[T, V],
zip: coproduct.ZipWithKeys.Aux[K, V, R],
ev: R <:< V
): Aux[T, R] =
new LabelledGeneric[T] {
type Repr = R
def to(t: T): Repr = zip(gen.to(t))
def from(r: Repr): T = gen.from(r)
}
}

class nonGeneric extends StaticAnnotation

0 comments on commit 9a6d70c

Please sign in to comment.