Encoder derivation fails for deeply nested classes
See original GitHub issueI encountered what looks like a bug in circe 0.14.0-M7
and Scala 3.0.0
. Right now, I cannot come up what exactly breaks the derivation. My assumption is it breaks when a class structure is “deeply” nested - when more derivations need to be generated.
import io.circe.{Encoder, Json}
import io.circe.syntax._
import io.circe.generic.semiauto._
object Main {
/* If Encoder[Foo] is not defined, compilation fails with
[error] 7 | given Encoder[Dto] = deriveEncoder[Dto]
[error] | ^^^^^^^^^^^^^^^^^^
[error] | cannot reduce summonFrom with
[error] | patterns : case given encodeA @ _:io.circe.Encoder[Seq[Main.Foo]]
[error] | case given evidence$1 @ _:deriving.Mirror.Of[Seq[Main.Foo]]
[error] | This location contains code that was inlined from Derivation.scala:14
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:12
[error] | This location contains code that was inlined from Derivation.scala:50
[error] | This location contains code that was inlined from semiauto.scala:27
If Endoder[Foo] is defined, compilation fails with:
[error] 18 | given Encoder[Foo] = deriveEncoder[Foo]
[error] | ^^^^^^^^^^^^^^^^^^
[error] | Maximal number of successive inlines (32) exceeded,
[error] | Maybe this is caused by a recursive inline method?
[error] | You can use -Xmax-inlines to change the limit.
[error] | This location contains code that was inlined from Main.scala:18
[error] | This location contains code that was inlined from Derivation.scala:16
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:12
[error] | This location contains code that was inlined from Derivation.scala:50
[error] | This location contains code that was inlined from Derivation.scala:16
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:12
[error] | This location contains code that was inlined from Derivation.scala:50
[error] | This location contains code that was inlined from Derivation.scala:16
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:12
[error] | This location contains code that was inlined from Derivation.scala:50
[error] | This location contains code that was inlined from Derivation.scala:16
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:12
[error] | This location contains code that was inlined from Derivation.scala:50
[error] | This location contains code that was inlined from Derivation.scala:16
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:12
[error] | This location contains code that was inlined from Derivation.scala:50
[error] | This location contains code that was inlined from Derivation.scala:16
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:12
[error] | This location contains code that was inlined from Derivation.scala:50
[error] | This location contains code that was inlined from Derivation.scala:16
[error] | This location contains code that was inlined from Derivation.scala:38
[error] | This location contains code that was inlined from Derivation.scala:12
[error] | This location contains code that was inlined from Derivation.scala:50
[error] | This location contains code that was inlined from semiauto.scala:27
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed
*/
given Encoder[Foo] = deriveEncoder[Foo]
given Encoder[Dto] = deriveEncoder[Dto]
case class Dto(elements: Seq[Foo])
case class Foo(bar: Option[Bar])
case class Bar(baz: Option[Baz])
case class Baz(qux: Qux)
case class Qux(a: Int)
}
Derivation for Seq[Foo]
is already mentioned here.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
circe/circe - Gitter
I'm trying to encode some json from a case class which has nested case classes. I've had a bit of a nightmare getting...
Read more >Unable to deserialise a nested class with NSCoding
I have a complex class with many nested classes to several levels deep which is serialised and stored in CoreData table. The problem...
Read more >Warnings and known issues - circe
For large or deeply-nested case classes and sealed trait hierarchies, the generic derivation provided by the generic subproject may stack overflow during ...
Read more >Where are all these 'deeply nested hierarchy' problems ...
If you derive from a class you need to know the inner workings of the class you derive from. Some functionality might depend...
Read more >Errors | Node.js v19.3.0 Documentation
Class : Error ... Errors that occur within Asynchronous APIs may be reported in multiple ... HTTP/2 ORIGIN frames are limited to a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/argonaut-io/argonaut/commit/ae11983a34986b9d9273295aad9c09a7079f95f0 Scala 3 recursive case classes example in another json library
@FabioPinheiro As far as I know there’s no regression here—this is a known issue with circe-generic’s fully automatic derivation on Scala 3 (see e.g. https://github.com/circe/circe/releases/tag/v0.14.0: “fully-automatic derivation does not currently support recursive case classes”).
There’s no timeline for this to be fixed. A fix is likely to fall out naturally from other planned improvements to the Shapeless-free generic derivation mechanism on Scala 3, but
generic.auto
support on Scala 3 in particular is unlikely to be a priority for me personally (unless someone wants to sponsor that work).