I am compiling a project with Scala 2.9.1 and getting
java.lang.AssertionError: assertion failed
at scala.Predef$.assert(Predef.scala:89)
at scala.tools.nsc.symtab.Symbols$Symbol.accessed(Symbols.scala:1142)
at scala.tools.nsc.symtab.Symbols$Symbol.accessed(Symbols.scala:1138)
at scala.tools.nsc.transform.Mixin$MixinTransformer$$anonfun$buildFieldPositions$1$1.apply(Mixin.scala:1006)
I guess it’s a bug, but I don’t really have time to fix it or wait for someone else to fix it, so I’d like to just change whatever I’m doing so I don’t hit the bug.
But I’m having a hard time because I get no clue about what part of my code caused the problem. Are there any strategies I can use to isolate the problem?
To make things easier for those investigating, here are the links to the source code:
I haven’t worked around Scala compiler crashes, in specific, but I have worked around other compiler crashes. What you want to do is to try narrowing down what’s causing the problem. The easiest way to do this in most projects is to do a binary search via commenting. That is, comment out about half of the code and see if the bug still happens. If not, uncomment that half and comment the other half and see if the bug still happens. Then, assuming that this works and you find which half it’s occurring in, break that in half via comments. Repeat this process until you’re down to the smallest segment of code which you can find which still breaks things. (Obviously, you may not always be able to do even halves due to code dependencies, but find ways to break it, at least, into big chunks).
When you get there, you may find, by inspection, that there is a bug in that code because compiler crashes, in my experience, are more likely to be caused by incorrectly formed code which is incorrectly formed in a manner that the compiler author didn’t expect. For example, my own intellisense-like Java module that I wrote for work would crash on
foo(super).barbecause I’d never imagined anyone not following super with a period or open paren but it could slip through the parser due to how the grammar was designed. And Adobe’s Actionscript compiler would crash when you wrotevar x:int : 10;rather thanvar x:int = 10;(they may have fixed that now, but it would crash there last time I used it). So, if you do find a bug in your code, fix it. If not, just try to rewrite that code so that it’s different. Hopefully you’ll be able to find a version which doesn’t cause a compiler crash.