如何解决 Scala 编译器崩溃? [英] How can I work around a Scala compiler crash?

查看:72
本文介绍了如何解决 Scala 编译器崩溃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Scala 2.9.1 编译一个项目并得到

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:

推荐答案

我还没有解决 Scala 编译器崩溃问题,具体来说,但我解决了其他编译​​器崩溃问题.您想要做的是尝试缩小导致问题的范围.在大多数项目中,最简单的方法是通过注释进行二分搜索.也就是说,注释掉大约一半的代码,看看错误是否仍然存在.如果没有,取消注释那一半并注释另一半,看看错误是否仍然发生.然后,假设这有效并且您发现它发生在哪一半,请通过评论将其分成两半.重复这个过程,直到你找到最小的代码段,你可以找到它仍然破坏事情.(显然,由于代码依赖性,您可能并不总是能够将其分成两半,但至少可以找到将其分解为大块的方法.

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).

当您到达那里时,您可能会通过检查发现该代码中存在错误,因为根据我的经验,编译器崩溃更有可能是由格式错误的代码导致的编译器作者没想到.例如,我自己为工作编写的类似智能感知的 Java 模块会在 foo(super).bar 上崩溃,因为我从来没有想过有人不会在 super 后面加上句点或打开括号,但它可以由于语法的设计方式,可以通过解析器.当您编写 var x:int : 10; 而不是 var x:int = 10; 时,Adobe 的 Actionscript 编译器会崩溃(他们现在可能已经解决了这个问题,但它会我上次使用它时在那里崩溃).因此,如果您确实在代码中发现了错误,请修复它.如果没有,只需尝试重写该代码以使其不同.希望您能找到一个不会导致编译器崩溃的版本.

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).bar because 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 wrote var x:int : 10; rather than var 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.

这篇关于如何解决 Scala 编译器崩溃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆