我正在尝试按如下方式运行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))
(extendedDefaults
查看object scala in compiler mirror not found - running Scala compiler programatically)。但是,我得到了测试失败,如
[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] ...
即使我没有使用任何并发。我该如何解决这个错误?
注意:找到答案,仍然张贴以防其他人遇到同样的问题。
答案 0 :(得分:1)
问题是使用了错误的Global
类;我必须导入scala.tools.nsc.Global
而不是scala.tools.nsc.interactive.Global
。