Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScriptEngine under sbt doesn't load/run #10058

Open
scabug opened this issue Nov 15, 2016 · 3 comments
Open

ScriptEngine under sbt doesn't load/run #10058

scabug opened this issue Nov 15, 2016 · 3 comments

Comments

@scabug
Copy link

scabug commented Nov 15, 2016

This version of the test at #8521 fails to find ScriptEngine under sbt.

Created directly, the compiler fails to initialize.

import javax.script._
import scala.tools.nsc.interpreter._

object Main extends App {

  val ngine = new ScriptEngineManager().getEngineByName("scala").asInstanceOf[ScriptEngine with Compilable]
  val iMain = ngine.asInstanceOf[Scripted].intp

  //val ngine = new Scripted.Factory().getScriptEngine.asInstanceOf[ScriptEngine with Compilable]
  //val iMain = ngine.asInstanceOf[Scripted].intp

  class Foo
  iMain.settings.embeddedDefaults[Foo]

  println(Thread.currentThread().getContextClassLoader)
  ngine.compile("val x = 1")
  println(Thread.currentThread().getContextClassLoader)
}
[info] Running checkcl.Main 
[error] (run-main-0) scala.reflect.internal.FatalError: class StringContext does not have a member f
scala.reflect.internal.FatalError: class StringContext does not have a member f
	at scala.reflect.internal.Definitions$DefinitionsClass.fatalMissingSymbol(Definitions.scala:1239)
	at scala.reflect.internal.Definitions$DefinitionsClass.$anonfun$getMember$1(Definitions.scala:1262)
	at scala.reflect.internal.Definitions$DefinitionsClass.getMember(Definitions.scala:1257)
	at scala.reflect.internal.Definitions$DefinitionsClass.getMemberMethod(Definitions.scala:1291)
	at scala.reflect.internal.Definitions$DefinitionsClass$RunDefinitions.StringContext_f$lzycompute(Definitions.scala:1478)
	at scala.reflect.internal.Definitions$DefinitionsClass$RunDefinitions.StringContext_f(Definitions.scala:1478)
	at scala.tools.reflect.FastTrack.$anonfun$fastTrackCache$1(FastTrack.scala:53)
	at scala.reflect.internal.SymbolTable$perRunCaches$$anon$1.apply(SymbolTable.scala:395)
	at scala.tools.reflect.FastTrack.contains(FastTrack.scala:20)
	at scala.tools.nsc.typechecker.Namers$Namer.methodSig(Namers.scala:1294)
[snip]
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5555)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:102)
	at scala.tools.nsc.Global$GlobalPhase.$anonfun$applyPhase$1(Global.scala:402)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:395)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.$anonfun$run$1(Analyzer.scala:94)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.$anonfun$run$1$adapted(Analyzer.scala:93)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:932)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:93)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1404)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1389)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1384)
	at scala.tools.nsc.interpreter.IMain._initialize(IMain.scala:129)
	at scala.tools.nsc.interpreter.IMain.initializeSynchronous(IMain.scala:149)
	at scala.tools.nsc.interpreter.Scripted.<init>(Scripted.scala:74)
	at scala.tools.nsc.interpreter.Scripted$.apply(Scripted.scala:309)
	at scala.tools.nsc.interpreter.Scripted$Factory.getScriptEngine(Scripted.scala:302)

@scabug
Copy link
Author

scabug commented Nov 15, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10058?orig=1
Reporter: @som-snytt
Affected Versions: 2.12.0
See #8521

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@tyrcho
Copy link

tyrcho commented May 27, 2017

This issue could be related : https://stackoverflow.com/questions/44217163/dynamic-compilation-with-scala-2-12-from-sbt-test (same stack trace, same goal to compile dynamically from sbt)

@scf37
Copy link

scf37 commented Aug 28, 2018

Root of the problem is that sbt for reason unknown runs tests with java system property java.class.path set to ...bin/sbt-launch.jar

I managed to make scala compiler work by using -javacp and passing different classpath collected from sbt:

sbtClasspath := {
      val cp = (fullClasspath in Test).value.map(x => x.data.getAbsolutePath).mkString(":")
      System.setProperty("sbt-classpath", cp)
}

This approach works up to Scala 2.12.4. 2.12.5 and up still fail with abovementioned exception.

max-leuthaeuser added a commit to joernio/joern that referenced this issue Oct 22, 2019
…during tests. Hence, 'new ScriptEngineManager().getEngineByName("scala")' always returns 'null'.

* enabled previously failed, and thus, ignored tests.
@SethTisue SethTisue added scripting and removed repl labels Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants