プロジェクトで scala-pickling を使用しようとしています。しかし、私はそれに問題があります。私がこのコードを持っていると仮定しましょう:
import scala.pickling._
import scala.pickling.Defaults._
import scala.pickling.json._
sealed trait State
case class Married(name:String) extends State
case object Single extends State
trait Person[T<:State] {
def name:String
def surname:String
def age:Int
def state:T
}
case class Male[T<:State](
val name:String,
val surname:String,
val age:Int,
val state:T) extends Person[T]
case class Female[T<:State](
val name:String,
val surname:String,
val age:Int,
val state:T) extends Person[T]
def hideType[T<:State]:Person[T] = Male("Hussein", "?", 145, Single).asInstanceOf[Person[T]]
しようとするとhideType.pickle
、コンパイル時エラーが発生します。
error: Cannot generate a pickler for Person[T]. Recompile with -Xlog-implicits for details
この場合、pickler/unpickler を生成する際の問題は何ですか?
より詳しい情報:
スカラ 2.11.6
スカラ酸洗 0.10.0
編集1:
「-Xlog-implicits」でコンパイルした結果:
[info] Loading global plugins from /home/someone/i/etc/sbt/0.13/plugins
[info] Loading project definition from /home/someone/tmp/pickling/project
[info] Set current project to pickling (in build file:/home/someone/tmp/pickling/)
[info] Compiling 1 Scala source to /home/someone/tmp/pickling/target/scala-2.11/classes...
[info] /home/someone/tmp/pickling/src/main/scala/com/example/Hello.scala:35: genPickler is not a valid implicit value for scala.pickling.Pickler[com.example.Person[T]] because:
[info] hasMatchingSymbol reported error: stepping aside: repeating itself
[info] hideType.pickle
[info] ^
[info] /home/someone/tmp/pickling/src/main/scala/com/example/Hello.scala:35: genPickler is not a valid implicit value for scala.pickling.Pickler[com.example.Person[T]] because:
[info] hasMatchingSymbol reported error: polymorphic expression cannot be instantiated to expected type;
[info] found : [T]scala.pickling.Pickler[T]
[info] required: scala.pickling.Pickler[com.example.Person[?]]
[info] hideType.pickle
[info] ^
[error] /home/someone/tmp/pickling/src/main/scala/com/example/Hello.scala:35: Cannot generate a pickler for com.example.Person[T]. Recompile with -Xlog-implicits for details
[error] hideType.pickle
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 2 s, completed May 26, 2015 4:31:45 AM