7

I created scala case class with 100 fields +- , When I'm trying to build the project (with gradle) , I'm getting error:

Cause: java.lang.StackOverflowError
    at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:698)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5396)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5423)

I'm using scala 2.11 , and found that in the past, there was a limitation of 22 fields. but it was fixed.

So why the build is failed? (I tried to increase -Xss20m , but it didn't help)

Ben Haim Shani
  • 265
  • 4
  • 15
  • Someone just reported this, either a project ticket or on SO. I think they had 200 fields for DB columns. They also tried huge stack for compilation. – som-snytt Jan 14 '19 at 22:12
  • Out of curiosity, how many fields does it take before this Stack Overflow error happens? – James Whiteley Jan 15 '19 at 09:54
  • with 96 fields. (95 fields the build successful) – Ben Haim Shani Jan 15 '19 at 11:27
  • I've just got exactly the same on 2.11.8. I can't even say there's a clear border where it starts getting broken. Somewhere around 95-96 indeed, but sometimes it saw the build breaking with a smaller number (between 85 and 90). So it doesn't seem to be bound to a specific number of arguments. – Vasiliy Galkin May 07 '20 at 08:56
  • I also faced the same issue. Anyone with a solution ? – Abba Jun 24 '20 at 12:29
  • Also having this issue. I am also building with Gradle from within IntelliJ and apparently, I have troubles passing -Xss to scala compiler. Has anyone found a way? – bazinac Jul 24 '20 at 09:16

1 Answers1

4

What worked in my case was setting -Xss in build.gradle script like this:

compileScala {
    options.forkOptions.jvmArgs += "-Xss4m"
}

Then I am able to compile app with case class having 100+ fields using scala 2.11.12. All the other settings (in IntelliJ Idea menus) were not effective.

bazinac
  • 668
  • 5
  • 22