amnaredo / test

0 stars 0 forks source link

[question] how to pickle scalaz.Tree #187

Open amnaredo opened 2 years ago

amnaredo commented 2 years ago

Hi guys,

I have the following case class

@JSExport("BomNode")
@JSExportAll
case class BomNode(nodeId: String, nodeType: Short, id: Long = -1) {

  def node(subForest: Tree[BomNode]*): Tree[BomNode] = Tree.Node(this, subForest.toStream)

  def leaf: Tree[BomNode] = Tree.Leaf(this)

}

When i try to

println(write(BomNode("a",1).node(BomNode("b",2).leaf)))

I receive the following error:

Error:(78, 18) The referenced trait [[Tree]] does not have any sub-classes. This may happen due to a limitation of scalac (SI-7046) given that the trait is not in the same package. If this is the case, the hierarchy may be defined using integer constants.
    println(write(tree))

And it's true that Tree doesn't have any sub-classes it is instantiated like


object Tree extends TreeInstances {
  /**
   * Node represents a tree node that may have children.
   *
   * You can use Node for tree construction or pattern matching.
   */
  object Node {
    def apply[A](root: => A, forest: => Stream[Tree[A]]): Tree[A] = {
      new Tree[A] {
        private[this] val rootc = Need(root)
        private[this] val forestc = Need(forest)
        def rootLabel = rootc.value
        def subForest = forestc.value

        override def toString = "<tree>"
      }
    }

    def unapply[A](t: Tree[A]): Option[(A, Stream[Tree[A]])] = Some((t.rootLabel, t.subForest))
  }

But, is any way to pickle/unpickle sealed abstract classes that doesn't have concrete instances with uPickle?

Regards, B.

ID: 169 Original Author: bobymicroby

amnaredo commented 2 years ago

+1

Original Author: tannerezell

amnaredo commented 2 years ago

Bug bankruptcy Original Author: lihaoyi