Skip to content

Commit

Permalink
fix 2.12 issue with lazy decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouyang committed Oct 15, 2020
1 parent 57a652a commit 7e69751
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/main/scala/us/oyanglul/dhall/generic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
}

0 comments on commit 7e69751

Please sign in to comment.