amnaredo / test

0 stars 0 forks source link

Support pickling case class with trait as parameter. #189

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

I have an expression AST implemented on top of

sealed trait IExpr

with case classes like

final case class Literal(v: Value)                                      extends IExpr
final case class NumericBinOpExpr(op: NumericBinOp, l: IExpr, r: IExpr) extends IExpr

When pickling a recursive expression, I get Error:(523, 17) diverging implicit expansion for type upickle.default.Writer[T1] starting with macro method macroW in trait LowPriX writeIExpr Error:(523, 17) diverging implicit expansion for type upickle.default.Writer[T1] starting with method SeqishW in trait Implicits writeIExpr Error:(523, 17) ambiguous implicit values: both value derive$macro$469 of type => upickle.default.Writer[[org].core.query.intermediate.LogicBinOp] and value derive$macro$271 of type => upickle.default.Writer[[org].core.query.intermediate.BooleanBinOpExpr] match expected type upickle.default.Writer[T1] writeIExpr Error:(523, 17) not enough arguments for method Tuple1W: (implicit evidence$1: upickle.default.Writer[T1])upickle.default.Writer[(T1,)]. Unspecified value parameter evidence$1. writeIExpr

A more contrived example, run in Jupyter notebook.

sealed trait IntOrTuple
case class IntThing(@key("i")i: Int) extends IntOrTuple
case class TupleThing(name: String, t: (Int, Int), @key("another2")another: IntOrTuple) extends IntOrTuple

val tupleThing = TupleThing("hello", (2,3), IntThing(3))
write\[IntOrTuple\](tupleThing)

gives

Main.scala:113: exception during macro expansion: java.lang.AbstractMethodError at derive.Derive.deriveClass(Derive.scala:351) at derive.Derive$$anonfun$9.apply(Derive.scala:238) at derive.Derive$$anonfun$9.apply(Derive.scala:234) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234) at scala.collection.immutable.Map$Map4.foreach(Map.scala:188) at scala.collection.TraversableLike$class.map(TraversableLike.scala:234) at scala.collection.AbstractTraversable.map(Traversable.scala:104) at derive.Derive.deriveType(Derive.scala:234) at derive.Derive.derive(Derive.scala:60) at upickle.Macros$.macroWImpl(Macros.scala:156)

writeIntOrTuple ^

Is there a workaround for this?

Thanks!

ID: 172 Original Author: gmachine1

amnaredo commented 3 years ago

Bug bankruptcy Original Author: lihaoyi