简体   繁体   中英

What is the practical maximum number of fields allowed in a Scala case class now that 22 is no longer the limit?

I have a project that is generating a compile-time stack overflow error.

I am using Quill for persistence, which uses macros. I have a case class with 600+ fields which represents a database table.

During compilation I get the following infinite recursion:

ervice.scala:27: UPDATE email_user SET password_hash = ? WHERE user_id = ? [info] .run(quote { [info] ^ java.lang.StackOverflowError at scala.tools.nsc.transform.Erasure$Eraser.adaptMember(Erasure.scala:686) at scala.tools.nsc.transform.Erasure$Eraser.typed1(Erasure.scala:773) at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5584) at scala.tools.nsc.typechecker.Typers$Typer.typedInternal(Typers.scala:5616) at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5557) at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5562) at scala.tools.nsc.typechecker.Typers$Typer.$anonfun$typed1$38(Typers.scala:4708) at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:698) at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4710) at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4757) at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5530) at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5547) at scala.tools.nsc.transform.Erasure$Eraser.type d1(Erasure.scala:773) at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5584)

Even though the 22 field limit on the number of case fields is now gone is there some practical limit I am bumping into?

This compile error occurs if I am not using Quill to access the table/huge case class in question.

Thanks for any insight!

You are bumping into the max stack size of the JVM you are compiling on, if you want to call that a practical limit. It's considered normal that you have to increase the stack size of the JVM if you want to compile code that is nested unusually deep, or uses unusually large case classes. By passing the argument -Xss6m to the JVM you can set the max stack size to 6MB. You can try to increase that number until it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM