diff --git a/src/main/scala/us/oyanglul/dhall/generic.scala b/src/main/scala/us/oyanglul/dhall/generic.scala index 3cc0e78..70c62bb 100644 --- a/src/main/scala/us/oyanglul/dhall/generic.scala +++ b/src/main/scala/us/oyanglul/dhall/generic.scala @@ -8,13 +8,27 @@ import shapeless.labelled.{FieldType, field} import shapeless._ import cats.syntax.either._ -trait LowPriorityForScala212Binary { +object generic { + implicit val decodeHNil: Decoder[HNil] = new Decoder[HNil] { + def decode(expr: Expr): Result[HNil] = HNil.asRight + def isValidType(typeExpr: Expr): Boolean = true + def isExactType(typeExpr: Expr): Boolean = true + } + + implicit val decodeCNil: Decoder[CNil] = new Decoder[CNil] { + def decode(expr: Expr): Result[CNil] = + Left(new DecodingFailure("Inconceivable! Coproduct never be CNil", expr)) + def isValidType(typeExpr: Expr): Boolean = true + def isExactType(typeExpr: Expr): Boolean = true + } + implicit def decodeGeneric[A, ARepr](implicit gen: LabelledGeneric.Aux[A, ARepr], - decoder: Decoder[ARepr] + decoder: Lazy[Decoder[ARepr]] ): Decoder[A] = new Decoder[A] { - def decode(expr: Expr): Result[A] = decoder.decode(expr).map(gen.from) + def decode(expr: Expr): Result[A] = + decoder.value.decode(expr).map(gen.from) def isValidType(typeExpr: Expr): Boolean = true def isExactType(typeExpr: Expr): Boolean = true } @@ -73,17 +87,3 @@ trait LowPriorityForScala212Binary { def isExactType(typeExpr: Expr): Boolean = true } } -object generic extends LowPriorityForScala212Binary { - implicit val decodeHNil: Decoder[HNil] = new Decoder[HNil] { - def decode(expr: Expr): Result[HNil] = HNil.asRight - def isValidType(typeExpr: Expr): Boolean = true - def isExactType(typeExpr: Expr): Boolean = true - } - - implicit val decodeCNil: Decoder[CNil] = new Decoder[CNil] { - def decode(expr: Expr): Result[CNil] = - Left(new DecodingFailure("Inconceivable! Coproduct never be CNil", expr)) - def isValidType(typeExpr: Expr): Boolean = true - def isExactType(typeExpr: Expr): Boolean = true - } -}