Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile error when encode a case class #34

Closed
djx314 opened this issue Aug 14, 2015 · 5 comments · Fixed by #58
Closed

Compile error when encode a case class #34

djx314 opened this issue Aug 14, 2015 · 5 comments · Fixed by #58

Comments

@djx314
Copy link
Contributor

djx314 commented Aug 14, 2015

I don't find the reason with the bug, just provide all I know.

[enuma] $ console
[info] Starting scala interpreter...
[info] 
import scalaz._
import Scalaz._
import io.circe._
import io.circe.generic.auto._
import io.circe.jawn._
import io.circe.syntax._
Welcome to Scala version 2.11.7 (OpenJDK 64-Bit Server VM, Java 1.8.0_51).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :paste
// Entering paste mode (ctrl-D to finish)

case class Aaaaa(
  id: Option[Long],
  trade111: Option[Long],
  trade222: Option[Long],
  trade333: Option[Long],
  trade444: Option[Long],
  enterprise: Option[Long]
)
case class Ccccc(name: String)
case class Bbbbb(energy: Aaaaa, street1: Ccccc, street2: Ccccc, street3: Ccccc)

//implicit val aabbcc = Encoder[Aaaaa]
val kk: Bbbbb = ???
kk.asJson

// Exiting paste mode, now interpreting.
//Tips: Here complete failed
<console>:43: error: diverging implicit expansion for type io.circe.Encoder[Bbbbb]
starting with method encodeCaseClass in trait GenericInstances
       kk.asJson
          ^

scala> :paste
// Entering paste mode (ctrl-D to finish)

case class Aaaaa(
  id: Option[Long],
  trade111: Option[Long],
  trade222: Option[Long],
  trade333: Option[Long],
  trade444: Option[Long],
  enterprise: Option[Long]
)
case class Ccccc(name: String)
case class Bbbbb(energy: Aaaaa, street1: Ccccc, street2: Ccccc, street3: Ccccc)

implicit val aabbcc = Encoder[Aaaaa]
val kk: Bbbbb = ???
kk.asJson

// Exiting paste mode, now interpreting.
//Tips: Here complete successfully
scala.NotImplementedError: an implementation is missing
  at scala.Predef$.$qmark$qmark$qmark(Predef.scala:225)
  ... 47 elided

scala> :paste
// Entering paste mode (ctrl-D to finish)

case class Aaaaa(
  id: Option[Long],
  trade111: Option[Long],
  enterprise: Option[Long]
)
case class Ccccc(name: String)
case class Bbbbb(energy: Aaaaa, street1: Ccccc, street2: Ccccc, street3: Ccccc)

//implicit val aabbcc = Encoder[Aaaaa]
val kk: Bbbbb = ???
kk.asJson

// Exiting paste mode, now interpreting.
//Tips: Here complete successfully
scala.NotImplementedError: an implementation is missing
  at scala.Predef$.$qmark$qmark$qmark(Predef.scala:225)
  ... 47 elided

scala> :paste
// Entering paste mode (ctrl-D to finish)

case class Aaaaa(
  id: Option[Long],
  trade111: Option[Long],
  enterprise: Option[Long]
)
case class Ccccc(name: String)
case class Bbbbb(energy: Aaaaa, street1: Ccccc)

//implicit val aabbcc = Encoder[Aaaaa]
val kk: Bbbbb = ???
kk.asJson

// Exiting paste mode, now interpreting.
//Tips: Here complete failed
<console>:40: error: diverging implicit expansion for type io.circe.Encoder[Bbbbb]
starting with method encodeCaseClass in trait GenericInstances
       kk.asJson
          ^

scala> :paste
// Entering paste mode (ctrl-D to finish)

case class Aaaaa(
  id: Option[Long],
  trade111: Option[Long],
  enterprise: Option[Long]
)
case class Ccccc(name: String)
case class Bbbbb(energy: Aaaaa, street1: Ccccc)

implicit val aabbcc = Encoder[Aaaaa]
val kk: Bbbbb = ???
kk.asJson

// Exiting paste mode, now interpreting.
//Tips: Here complete successfully
scala.NotImplementedError: an implementation is missing
  at scala.Predef$.$qmark$qmark$qmark(Predef.scala:225)
  ... 47 elided

scala> 

It seems that sometimes I have to provide implicit val aabbcc = Encoder[Aaaaa], and it looks like that complete always successfully when I provide the implicit val aabbcc = Encoder[Aaaaa], and sometimes fail when I just type kk.asJson without implicit.
Any fix or suggest?

@vkostyukov vkostyukov changed the title Complete error when encode a case class simetimes. Compile error when encode a case class Aug 14, 2015
@djx314
Copy link
Contributor Author

djx314 commented Aug 14, 2015

Oh, I forgot it, when decode a case class like it provide above, it used to provide some Decoder of the class that defined in properties sometimes(Just sometimes and I don't know when). It looks like the same as the json encode problem above.

@travisbrown
Copy link
Member

Thanks for the report! I'm at a conference today but I'll take a look this evening.

@alexarchambault
Copy link
Contributor

@travisbrown I tried to port my latest developments from argonaut-shapeless here, see https://github.com/alexarchambault/circe/commits/topic/generic. These seem to fix this issue, but rely on new developments in shapeless (milessabin/shapeless#435), not merged in mainline yet.

I've been trying to fix it without overhauling the generic module, without success (fixing it was breaking other things), but hopefully you'll have more luck than me at this.

I tried to use export-hook too, which didn't work either, but I haven't investigated much the problem.

@travisbrown
Copy link
Member

Thanks, @alexarchambault! I'd like to spend a little bit of time understanding what's going on in your generic branch, and how it relates to export-hook, and since I'm at Scala by the Bay today that probably won't happen until tomorrow.

I've also just created #36 and #37 to highlight some issues related to ObjectEncoder and tuple instances, which I think complicates some things and simplifies others.

@travisbrown
Copy link
Member

The error message situation is a little better after #43, but it doesn't fix this and the message still isn't great:

// Exiting paste mode, now interpreting.

<console>:38: error: could not find implicit value for parameter e: io.circe.Encoder[Bbbbb]
       kk.asJson
          ^

julienrf pushed a commit to scalacenter/circe that referenced this issue May 13, 2021
julienrf pushed a commit to scalacenter/circe that referenced this issue May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants