【问题标题】:Race condition detected when compiling Scala file programmatically以编程方式编译 Scala 文件时检测到竞态条件
【发布时间】:2015-02-02 07:41:57
【问题描述】:

我正在尝试按如下方式运行 Scala 编译器:

val settings = new Settings
settings.usejavacp.value = true
settings.embeddedDefaults[LmsCompiler]
val compilerOptions = "-d" :: jarPath :: config.extraCompilerOptions.toList
settings.processArguments(compilerOptions, false)
val reporter = new StoreReporter
val compiler: Global = new Global(settings, reporter)
val run = new compiler.Run
run.compile(List(srcFile))

(请参阅 object scala in compiler mirror not found - running Scala compiler programatically 了解 extendedDefaults)。但是,我遇到了类似的测试失败

[info] - logicalOps *** FAILED ***
[info]   java.lang.AssertionError: assertion failed: Race condition detected: You are running a presentation compiler method outside the PC thread.[phase: <no phase>] Please file a ticket with the current stack trace at https://www.assembla.com/spaces/scala-ide/support/tickets
[info]   at scala.tools.nsc.interactive.Global.assertCorrectThread(Global.scala:452)
[info]   at scala.reflect.internal.Symbols$Symbol.rawInfo(Symbols.scala:1298)
[info]   at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1239)
[info]   at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:43)
[info]   at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:40)
[info]   at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:40)
[info]   at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:61)
[info]   at scala.reflect.internal.Mirrors$RootsBase.getClassByName(Mirrors.scala:99)
[info]   at scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(Mirrors.scala:102)
[info]   at scala.tools.nsc.backend.jvm.GenASM$AsmPhase.<init>(GenASM.scala:42)
[info]   ...

即使我没有使用任何并发。我该如何解决这个错误?

注意:找到了答案,如果其他人有同样的问题,仍然会发布。

【问题讨论】:

    标签: scala


    【解决方案1】:

    问题是使用了错误的Global 类;我必须导入 scala.tools.nsc.Global 而不是 scala.tools.nsc.interactive.Global

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 2015-03-09
      • 1970-01-01
      • 1970-01-01
      • 2018-01-21
      相关资源
      最近更新 更多