scala / pickling

Fast, customizable, boilerplate-free pickling support for Scala
lampwww.epfl.ch/~hmiller/pickling
BSD 3-Clause "New" or "Revised" License
831 stars 79 forks source link

Pickling case classes with objects and supertypes #18

Closed tomasherman closed 11 years ago

tomasherman commented 11 years ago

Hi,

i am having some problems with pickling. It seems to be doing something odd when trying to pickle case classes that contain objects. Consider this REPL session:

scala> import scala.pickling._; import json._
import scala.pickling._
import json._

scala> trait A
defined trait A

scala> case class B(x: Option[Int]) extends A
defined class B

scala> B(Some(1)).pickle.unpickle[B] == B(Some(1))
res1: Boolean = true 

scala> B(None).pickle.unpickle[B] == B(None)
res2: Boolean = true

scala> B(None).pickle.unpickle[A]
res4: A = B(None)

!!!!!!!!!
scala> B(None).pickle.unpickle[A] == B(None)
res3: Boolean = false 
!!!!!!!!!

scala> (B(None): A) == B(None)
res6: Boolean = true

As you can see, there is something odd going on with == method going on in the highlighted example above. Am i doing something wrong? This happens only if we unpickle B using the unpickle[A] method (as far as i know) Thanks, Tomas

phaller commented 11 years ago

I can't reproduce this outside of the REPL. Can you verify that this problem only happens in the REPL?

tomasherman commented 11 years ago

Sorry, yeah, it seems so. I was having some issues with pickling but they are fixed now. I thought this was the problem but it wasn't. Thanks for the effort!