Scala compiler bug, SOE on scala.reflect scala/bug

Team…

I am receiving the following issue when building some existing scala code. I am on version 0.13 of sbt, 1.8.113 of java 8 and scala 2.12.2.

java.lang.StackOverflowError
at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:714)
at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123)
at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:716)
at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123)
at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:716)
at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123)
at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:716)
at scala.reflect.internal.tpe.TypeMaps$TypeMap.mapOver(TypeMaps.scala:123)
at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:716)
at scala.reflect.internal.tpe.TypeMaps$SubstMap.apply(TypeMaps.scala:685)
at scala.collection.immutable.List.loop$1(List.scala:173)

Can someone please help me with this issue?

Thanks!!!
siliconplains

You’ve indicated elsewhere that you think https://github.com/scala/bug/issues/9142 may be the problem. That certainly seems plausible. It would be hard to say anything further without knowing more about the code that’s triggering the problem. (As in, you’d need to reduce your code to minimal code that triggers the problem, and then we’d see if what you end up with is basically the same as Denys’s example in the ticket, or if there’s something notably different about it.)

The only workaround I can think of to suggest for that issue is “don’t use recursive type aliases involving structural types”.

Thanks for the response Seth. I inherited a 70 scala file project that contains the offending code. When I build the software in SBT it does not tell me what line of code the SOE is occurring from. Can you tell me how to get the scalac to tell me where the offending line of code is? Is there a quick and easy way to narrow it down?

Thanks!!!
Allan

Alright, I set the verbose flag in the compiler and it came up with this.

[info] [typer in 227513ms]
[info] [loaded class file C:\Users\User.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.11.7.jar(scala/MatchError.class) in 0ms]
[trace] Stack trace suppressed: run last compile:compileIncremental for the full output.
[error] (compile:compileIncremental) java.lang.StackOverflowError
[error] Total time: 234 s, completed Jun 18, 2017 3:07:04 PM
[satalyte-api] $ last compile:compileIncremental

Based on what I am seeing, it appears the scala compiler is compiling something in the 2.11.7 jar file and that is causing the error. How do I fix something in the scala library like this?

Thanks!!!
Allan

That’s unlikely—and there’s nothing to compile in scala-library-2.11.7.jar. The compiler is failing some time it loads some compiled code, but that does not necessarily mean the code it loaded causes the issue.

I’d recommend doing a binary search on your code — either on the VCS history (if you have some) or on the source itself. I can’t find a very good explanation, but answers to this StackOverflow questions are a reasonable starting point: https://stackoverflow.com/q/843909/53974.
EDIT: this one in particular: https://stackoverflow.com/a/843922/53974

some even more specific binary search advice: https://stackoverflow.com/questions/8108127/how-can-i-work-around-a-scala-compiler-crash

Please post a gist with the full stack trace. You might need to run last compile:compileIncremental to see that if SBT suppresses it by default.

It can also be helpful to run with -Ytyper-debug -Ylog:all to try to get an idea about what part of the code and compiler intersected just before the crash. You’ll get reams of output, but the end of the log can be interesting.

You can also attach a debugger to the compiler with a breakpoint set on the StackOverflowError. sbt -jvm-debug 5006 compile should open up a remote debug port. Add "org.scala-lang" % "scala-compiler" % "2.11.7" as an libraryDependency to a SBT project and import that into your IDE, or manually add the following to the IDE classpath:

$HOME/.ivy2/cache/org.scala-lang/scala-compiler/jars/scala-compiler-2.11.7.jar
$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.7.jar

Then attach the debugger.