Open bbarker opened 6 years ago
There is no way a macro could generate a pickler for such trait as it has no type parameters and no implementations, and could contain anything. Container types must have a way to reference the pickler for the contained data, You'll have to provide your own, custom pickler for such types.
@bbarker What you are seeing here is one of the annoyances of scala's initializers, you have defined an implicit pickler in the jobwrap companion:
implicit val jwPickler: Pickler[JobWrap] = generatePickler[JobWrap]
Now, in the shapeless module, generatePickler is defined like this:
def generatePickler[T](implicit pickler: Pickler[T]): Pickler[T] = pickler
So, when calling generatePickler
on the rhs of the implicit val jwPickler
, it will resolve the implicit pickler with the currently uninitialized field jwPickler
. In this case, the pickler is null
. If you just try to call generatePickler without the implicit in scope, it will tell you that there is no derivable pickler.
In the normal boopickle.Default
object, we defined the generatePickler
method in a different way. It calls a macro directly. With shapeless, we get that implicitly.
@ochrons It think, we should make both functions behave the same way in order to avoid this unexpected behavior. But not sure yet, how we could do this here. What do you think?
This occurs in both JS and the JVM; I packaged up a somewhat minimal example of this. Here is the problematic trait:
JVM errror:
JS error: