Stack overflow error when nesting a case class and its companion object inside a method
See original GitHub issueCompiler version
I have just raised this issue for scala 2.12 and 2.13 (https://github.com/scala/bug/issues/12435) but it seems to also apply to scala 3.
Minimized code
def method(): Unit = {
final case class Person(name: String)
object Person {
val me = Person("Cameron")
}
val _ = Person.me
}
method()
Output
java.lang.StackOverflowError
Expectation
Expected output is Unit. This happens if I change the val to a lazy val or def. I also get the expected output if I use the “new” keyword to construct the instance of my case class
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (8 by maintainers)
Top Results From Across the Web
Stack overflow error when nesting a case class and its ...
using Scala 2.12 and 2.13 I get a java.lang.StackOverflowError when I run the following code: def method(): Unit = { final case class...
Read more >Case class companion object generation error for compound ...
When the migration is complete, you will access your Teams at stackoverflowteams.com, and they will no longer appear in the left sidebar on...
Read more >Is this a language bug or expected behaviour when nesting ...
I am getting an unusual stack overflow exception which may be a language bug. The issue arrises when I nest a class and...
Read more >Type classes and generic derivation - Travis Brown
The Stack Overflow question asks for a solution to a simple parsing problem: we've got some case classes like this: case class Person(name: ......
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 >
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 Free
Top 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
There is some speculation on the scala 2 issue. I think a good compromise for common use cases may suffice.
Minimized to