question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stack overflow error when nesting a case class and its companion object inside a method

See original GitHub issue

Compiler 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
som-snyttcommented, Jul 28, 2021

There is some speculation on the scala 2 issue. I think a good compromise for common use cases may suffice.

2reactions
nicolasstuckicommented, Jul 27, 2021

Minimized to

object Person {
  def apply(): Unit = ???
  val me = Person.apply()
}
@main def app = Person.me
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found