droste icon indicating copy to clipboard operation
droste copied to clipboard

derived Traverse fails on case objects

Open ceedubs opened this issue 7 years ago • 1 comments

Consider the following Option-like ADT:

@deriveTraverse
sealed abstract class MyExprF[+A] extends Product with Serializable

object MyExprF {
  final case class Const[+A](value: A) extends MyExprF[A]
  case object Noll extends MyExprF[Nothing]
}

The derived traverse method in the Traverse instance throws a MatchError on the Noll case:

scala> import cats.implicits._
import cats.implicits._

scala> val c: MyExprF[Int] = Const(3)
c: qq.droste.examples.MyExprF[Int] = Const(3)

scala> c.traverse(Option.apply) // expected output
res0: Option[qq.droste.examples.MyExprF[Int]] = Some(Const(3))

scala> val n: MyExprF[Int] = Noll
n: qq.droste.examples.MyExprF[Int] = Noll

scala> n.traverse(Option.apply) // I would expect Some(Noll)
scala.MatchError: Noll (of class qq.droste.examples.MyExprF$Noll$)
  at qq.droste.examples.MyExprF$$anon$1.traverse(TestExpr.scala:6)
  at qq.droste.examples.MyExprF$$anon$1.traverse(TestExpr.scala:6)
  at cats.Traverse$Ops.traverse(Traverse.scala:19)
  at cats.Traverse$Ops.traverse$(Traverse.scala:19)
  at cats.Traverse$ToTraverseOps$$anon$3.traverse(Traverse.scala:19)
  ... 36 elided

ceedubs avatar Sep 09 '18 15:09 ceedubs

@ceedubs thanks for the report! the derivation code is not very polished yet, so this kind of examples help a lot.

I'll try to put some work into it soon!

pepegar avatar Sep 10 '18 13:09 pepegar