amnaredo / test

0 stars 0 forks source link

Can `read` to a type which has nested `Seq` field referenced to self #122

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

My code:

import upickle._
read[Category](json)  // !!! can't compile

and related code is:

case class Category(id: String, name: String, projects: Seq[Project], description: Option[String] = None)

case class Project(id: String,
                   name: String,
                   linkGroups: Seq[LinkGroup] = Nil,
                   description: Option[String] = None,
                   stars: Option[Int] = None,
                   subProjects: Seq[Project] = Nil)

case class LinkGroup(id: String, name: String, links: Seq[Link] = Nil)

case class Link(id: String, name: Option[String] = None, url: String, description: Option[String] = None, showUrl: Boolean = true)

It can't compiled and failed on this line:

https://github.com/lihaoyi/upickle/blob/master/upickle/shared/src/main/scala/upickle/Macros.scala#L32

if (tpe.typeSymbol.fullName.startsWith("scala."))
        c.abort(c.enclosingPosition,s"this may be an error, can not generate Reader[$tpe <: ${tpe.typeSymbol.fullName}]")

I added some logging to print the value of tpe.typeSymbol.fullName, and found it:

Warning:scala: tpe.typeSymbol.fullName: scala.collection.Seq

Not sure where is wrong, and how to fix it?

ID: 82 Original Author: freewind

amnaredo commented 3 years ago

I found if I removed the subProjects: Seq[Project] = Nil from Project, the compilation will be good

Original Author: freewind

amnaredo commented 3 years ago

This is a duplicate of #30.

Original Author: tindzk

amnaredo commented 3 years ago

Yep, let's keep the discussion in one place

Original Author: lihaoyi