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

Compiler Warning with Value Classes #207

Open dzufferey opened 10 years ago

dzufferey commented 10 years ago

steps (0.10.0)

scala> import scala.pickling._, Defaults._, json._
import scala.pickling._
import Defaults._
import json._

scala> class ProcessID(val id: Short) extends AnyVal
defined class ProcessID

scala> new ProcessID(1).pickle
<console>:19: warning: ProcessID and Null are unrelated: they will always compare unequal
              new ProcessID(1).pickle
                               ^
res0: scala.pickling.json.pickleFormat.PickleType =
JSONPickle({
  "$type": "ProcessID",
  "id": 1
})

problem

<console>:19: warning: ProcessID and Null are unrelated: they will always compare unequal

original report

When (un)pickling value classes, the compiler produce a warning that looks like:

MyValueClass and Null are unrelated: they will always compare unequal

Pickling code produces a correct result. So this is more cosmetic than an issue.

tested with scala 2.11.2 and pickling 0.9.0-SNAPSHOT

The full warning looks like:

[warn] .../round/src/test/scala/example/DynamicMembership.scala:280: round.ProcessID and Null are unrelated: they will always compare unequal
[warn]     val (v,inst,id,replicas) = msg.getContent[(Int,Short,Short,List[Replica])]
[warn]                                              ^

the getContent method (of Message class) is defined as:

def getContent[A: SPickler: Unpickler: FastTypeTag]: A = {
  val bytes = getPayLoad //returns an Array[Byte]
  val converted = BinaryPickle(bytes).unpickle[A]
  converted
}

ProcessID and replica are defined as:

class ProcessID(val id: Short) extends AnyVal
case class Replica(id: ProcessID, address: String, port: Int)

source code at https://github.com/dzufferey/round let me know if you need more info.

eed3si9n commented 9 years ago

I was able to reproduce this problem using Pickling 0.10.0.