You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example that reproduces the problem uploaded to Github
Full description of the issue provided (see below)
Commit or Tag Version
v1.9.1
Expected Behaviour
Serializing a value of custom type using an implicit FromTo instance created with bimap() should work.
Note: The equivalent code for uPickle works as expected.
Actual Behaviour
The following error occurs using weePickle 1.9.1 with Scala 2.13.12:
Exception in thread "main" java.lang.ClassCastException:classcom.rallyhealth.weepickle.v1.core.Types$To$Delegate
cannot be cast to classcom.rallyhealth.weepickle.v1.core.Types$Tagged
(com.rallyhealth.weepickle.v1.core.Types$To$Delegate and com.rallyhealth.weepickle.v1.core.Types$Tagged are in unnamed module of loader 'app')
at com.rallyhealth.weepickle.v1.core.Types.com$rallyhealth$weepickle$v1$core$Types$$findTagName(Types.scala:133)
at com.rallyhealth.weepickle.v1.core.Types$TaggedTo$Node.<init>(Types.scala:286)
at com.rallyhealth.weepickle.v1.core.Types$To$.merge(Types.scala:97)
at stdin$.delayedEndpoint$stdin$1(stdin:9)
at stdin$delayedInit$body.apply(stdin:65534)
at scala.Function0.apply$mcV$sp(Function0.scala:42)
at scala.Function0.apply$mcV$sp$(Function0.scala:42)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1(App.scala:98)
at scala.App.$anonfun$main$1$adapted(App.scala:98)
at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:576)
at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:574)
at scala.collection.AbstractIterable.foreach(Iterable.scala:933)
at scala.App.main(App.scala:98)
at scala.App.main$(App.scala:96)
at stdin$.main(stdin:65534)
at stdin.main(stdin)
Steps to Reproduce
Paste this snippet into a shell (requires Scala CLI):
scala-cli run -<<END//>usingscala2.13.12//>usingdepcom.rallyhealth::weepickle-v1:1.9.1importcom.rallyhealth.weejson.v1.{Str, Value}
importcom.rallyhealth.weepickle.v1.WeePickle.{FromScala, FromTo, macroFromTo}
classCustom(a: String)
implicitvalfromTo:FromTo[Custom] = macroFromTo[Value].bimap[Custom](
_ =>Str(""),
_ =>newCustom(""),
)
FromScala(Custom(""))
END
The issue here is that Value is a sealed trait, but does not declare the discriminator that macroFromTo requires of sealed traits. However, you shouldn't need it -- Value is already defined as its own visitor, and FromValue and ToValue are already defined by default. If, instead of using macroFromTo[Value] here, you used fromTo[Value] (which will implicitly join the implicit FromValue and ToValue definitions as a FromTo), then everything should work as expected. (And it should compile a tiny bit faster, since no macro is required.)
Task List
Commit or Tag Version
v1.9.1
Expected Behaviour
Serializing a value of custom type using an implicit
FromTo
instance created withbimap()
should work.Note: The equivalent code for uPickle works as expected.
Actual Behaviour
The following error occurs using weePickle
1.9.1
with Scala2.13.12
:Steps to Reproduce
Paste this snippet into a shell (requires Scala CLI):
Related Code
Further comments
The type cast error is caused by this function in Types.scala:
The function assumes that will always recieve a sequence of
TaggedFromTo
but this is apparently not guaranteed.This function seems to be invoked by this part of the FromTo derivation macro in MacroImplicits.scala:
The text was updated successfully, but these errors were encountered: