1

I am trying to run Scala compiler as follows:

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

(see object scala in compiler mirror not found - running Scala compiler programatically for extendedDefaults). However, I get test failures like

[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]   ...

even though I am not using any concurrency. How can I fix this error?

Note: found the answer, still posting in case someone else has the same problem.

Community
  • 1
  • 1
Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

1 Answers1

1

The issue was using the wrong Global class; I had to import scala.tools.nsc.Global instead of scala.tools.nsc.interactive.Global.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487