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

scala.ScalaReflectionException: type T is not a class #164

Open lihaoyi opened 10 years ago

lihaoyi commented 10 years ago
[info] /Users/haoyi/Dropbox (Personal)/Workspace/autowire/jvm/src/test/scala/autowire/InteropTests.scala:124: pickling.this.Unpickler.genUnpickler is not a valid implicit value for scala.pickling.Unpickler[T] because:
[info] exception during macro expansion:
[info] scala.ScalaReflectionException: type T is not a class
[info]  at scala.reflect.api.Symbols$SymbolApi$class.asClass(Symbols.scala:272)
[info]  at scala.reflect.internal.Symbols$SymbolContextApiImpl.asClass(Symbols.scala:82)
[info]  at scala.pickling.UnpicklerMacros$$anonfun$impl$2.apply(Macros.scala:192)
[info]  at scala.pickling.UnpicklerMacros$$anonfun$impl$2.apply(Macros.scala:186)
[info]  at scala.pickling.Macro.preferringAlternativeImplicits(Tools.scala:368)
[info]  at scala.pickling.UnpicklerMacros$class.impl(Macros.scala:186)
[info]  at scala.pickling.Compat$$anon$3.impl(Compat.scala:29)
[info]  at scala.pickling.Compat$.UnpicklerMacros_impl(Compat.scala:30)
[info]           JSONPickle(s).unpickle[T]
[info]                                 ^

Clone this particular revision

https://github.com/lihaoyi/autowire/commit/5fc3066aef81fbe62939505bcdaf0e37740c3c4a#diff-826e9a6ed74accfd3512bcd6279d3bc7R109

And hit sbt jvm/test to repro.

I have no idea why it's blowing up; all I know is that it is ^_^

lihaoyi commented 10 years ago

That revision is on 0.8.0, but I just reproduced on 0.9.0-SNAPSHOT

coreyauger commented 9 years ago

I am receiving this error as well.

[error] scala.ScalaReflectionException: type T is not a class
[error]     at scala.reflect.api.Symbols$SymbolApi$class.asClass(Symbols.scala:275)
[error]     at scala.reflect.internal.Symbols$SymbolContextApiImpl.asClass(Symbols.scala:84)
[error]     at upickle.Macros$.picklerFor(Macros.scala:75)
[error]     at upickle.Macros$.macroRImpl(Macros.scala:35)
[error]         upickle.read[T](d)

I am attempting to write a responder using the following syntax...

socket.addResponder[List[Auth.SurfKitUser]]("Auth","friends"){
      f =>
        println(s"friends.. $f")
    }

The add responder stores the method and deserializes to the type expected for the callback

def addResponder[T >: upickle.Types](module:String, op:String)(responder:(T) => Unit) = {
    val key = s"$module-$op"
    def hook(d:String):Unit = {
      Try {
        upickle.read[T](d)
      } match{
        case Success(data) => responder(data)
        case Failure(e) =>
          println(s"Responder Failed to serialize to type..")
          println(s"${e}")
      }
    }
    val list:List[(String) => Unit] = hook _ :: responders.get(key).getOrElse(List[(String) => Unit]())
    responders += (key -> list)
  }

Any idea why this is failing? I am greatfull for any guidance you can provide :)