I am getting an unusual stack overflow exception which may be a language bug. The issue arrises when I nest a class and its companion object inside a method.
The following (pointless) code prints “Done!” without a problem:
object Foo extends App {
final case class Person(name: String)
object Person {
val me = Person("Cameron")
}
val _ = Person.me
println("Done!")
}
However if I nest some of it in a method the code still compiles, but throws an exception:
object Foo extends App {
def method(): Unit = {
final case class Person(name: String)
object Person {
val me = Person("Cameron")
}
val _ = Person.me
}
method()
println("Done!")
}
I used Scala 2.13 to try this out, but first noticed the bug when using 2.12.
Could someone tell me if this is expected behaviour? It seems like it could be a language bug to me?