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

derived Traverse fails on case objects #72

Open
ceedubs opened this issue Sep 9, 2018 · 1 comment
Open

derived Traverse fails on case objects #72

ceedubs opened this issue Sep 9, 2018 · 1 comment
Assignees

Comments

@ceedubs
Copy link
Contributor

ceedubs commented Sep 9, 2018

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 added a commit to ceedubs/droste that referenced this issue Sep 9, 2018
This required implementing my own Traverse instance. See [this issue](higherkindness#72).
@pepegar pepegar assigned pepegar and unassigned pepegar Sep 10, 2018
@pepegar
Copy link
Member

pepegar commented Sep 10, 2018

@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 pepegar self-assigned this Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants