How can I get around a Scala compiler crash?

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 suppose this is a mistake, but in fact I don’t have time to fix it or wait for someone to fix it, so I would just like to change what I’m doing so that I don’t get into the error.

But it’s hard for me because I don’t understand which part of my code caused the problem. Are there any strategies you can use to isolate the problem?

To facilitate the task for researchers, here are links to the source code:

+3
scala
source share
4 answers

I did not work with Scala compiler crashes in particular, but I worked on other compiler crashes. What you want to do is try to narrow down the cause of the problem. The easiest way to do this in most projects is to do a binary search through commenting. That is, comment on about half of the code and see if an error still occurs. If not, uncomment this half and comment on the other half and see if an error still occurs. Then, assuming this works, and you find which half of them happens, break it in half through the comments. Repeat this process until you get to the smallest code segment that you can find that still breaks things. (Obviously, you cannot always do even halves due to code dependencies, but find ways to break it into at least large chunks).

When you get there, you can find out by checking that there is an error in this code, because the compiler crashes, in my experience, are most likely caused by malformed code that is malformed in such a way that the compiler did not expect. For example, my own intellisense-like module that I wrote for work would crash on foo(super).bar because I never thought anyone would follow super with a period or open pair, but it can slip through the parser due to being designed. And the Adobe ActionScript compiler will fail when you write var x:int : 10; , not var x:int = 10; (maybe they fixed it now, but the last time I messed it up). So, if you find an error in your code, fix it. If not, try rewriting this code so that it is different. We hope you can find a version that will not cause the compiler to crash.

+2
source share

If you can get your code to do println at compile time, I'm sure you could cut it as soon as possible. So why not do something equivalent?

 0.0.0 // Lexer will choke on this (I think) val var; // Parser will choke on this val Some(x) = None; // Second pass will, I think, choke on this Option(2) match { case Some(x) => x } // Will emit warning in late phase and continue 

You can delete them in your code in different places as tests to find out how far the compiler can choke on this; this should allow you to narrow down to a few lines, where it might be more appropriate to comment / uncomment blocks of code.

Also, make sure you create from scratch when you come across something like this; the compiler sometimes dies when there are incompatible versions, and it does not recognize that it needs to recompile something in order to get the changes.

+2
source share

If you use the control source and work gradually (you use using the control source and work gradually, yes?), Then you already know what caused the problem - this is the last thing you changed, since you worked gradually, this will be a small change, and since you are using a control source, you know exactly what it is because you have a complete history of everything you have done.

Reduce this change to the smallest change that still reproduces the problem (most likely with a binary chop). Something about this change will be "weird" and this will confuse the compiler. Find a way to solve the problem without using any of this "weird" stuff, and you have a workaround.

But before you do this, report an error (any case where a compiler failure is definitely an error), as well as a small example to illustrate it.

If you did not work gradually and with the help of a control source, you have a much more tedious task:

  • First find out which file is causing the problem (use binary chopping to narrow it down until you define one file).
  • Then determine which bit of this file is causing the problem (binary chop again).
  • Keep binary chopping until you have one simple change.
+1
source share

The Scala trunk prints more information, so if you can compile it using a trunk to get a better error message, this will help. Of course, it is possible that this error is not in the trunk, but it is worth it.

If compiling with the body does not help, here is what I know. This is due to getters and setters. From the code, it can be either a setter or a receiver. This seems to be what is called when a getter or setter is used, not a specific one. You can find them.

In addition, pay attention to the rules for obtaining and installing. A getter must have at least the same visibility as the setter (i.e.Public if the setter is open, etc.). And since we are talking about a compiler error here, I would avoid strange appearances (i.e. Nothing but public or private), inheritance, or mixed visibility (e.g. setter private and getter public).

EDIT: I just noticed that mixin is mentioned in the stack trace. Thus, it is associated with a getter or setter, which is defined in the trait and used in the class or used by trait.

EDIT 2: Continuing the investigation. Do you have overloaded getters / setters for lazy shafts, or getters / setters overloaded with lazy shafts? Or, just lazy shafts to hell? I saw something in the third line of the track, which seems to indicate a lazy val.

If you find more information, try reproducing a small case to post a question.

+1
source share

All Articles