Navigation Menu

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

REPL javax.script eval is cached result #7933

Closed
scabug opened this issue Oct 25, 2013 · 3 comments
Closed

REPL javax.script eval is cached result #7933

scabug opened this issue Oct 25, 2013 · 3 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Oct 25, 2013

Reminder to fix.

scala> new IMain.Factory
res2: scala.tools.nsc.interpreter.IMain.Factory = scala.tools.nsc.interpreter.IMain$Factory@352b9aeb

scala> .getScriptEngine
res3: javax.script.ScriptEngine = scala.tools.nsc.interpreter.IMain@7505d7e7

scala> .asInstanceOf[Compilable]
res4: javax.script.Compilable = scala.tools.nsc.interpreter.IMain@7505d7e7

scala> .compile("val foo = 8")
res5: javax.script.CompiledScript = scala.tools.nsc.interpreter.IMain$WrappedRequest@749ccfd1

scala> .eval
res6: Object = 8

scala> res4 compile """println("hello") ; val bar = 8"""
res7: javax.script.CompiledScript = scala.tools.nsc.interpreter.IMain$WrappedRequest@7772d5dd

scala> res7.eval
hello
res8: Object = 8

scala> res7.eval
res9: Object = 8
@scabug
Copy link
Author

scabug commented Oct 25, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7933?orig=1
Reporter: @som-snytt

@scabug
Copy link
Author

scabug commented Jan 30, 2014

@rjolly said:
Attempted solution in scala/scala#3433

@scabug scabug closed this as completed Feb 10, 2014
@scabug
Copy link
Author

scabug commented Sep 18, 2015

@som-snytt said:
This means compile and eval have different semantics with respect to REPL history:

scala> val e = engine.asInstanceOf[ScriptEngine with Compilable]
e: javax.script.ScriptEngine with javax.script.Compilable = scala.tools.nsc.interpreter.IMain@1f28c152

scala> val s = e.compile("val x = 42")
s: javax.script.CompiledScript = $anon$1@4e423aa2

scala> s.eval()
res0: Object = ()

scala> e.eval("x")
<console>:11: error: not found: value x
       x
       ^
javax.script.ScriptException: compile-time error
  at scala.tools.nsc.interpreter.IMain.compiled(IMain.scala:600)
  at scala.tools.nsc.interpreter.IMain.eval(IMain.scala:1066)
  at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
  ... 33 elided

scala> e.eval("val x = 42")
res2: Object = 42

scala> e.eval("x")
res3: Object = 42

@scabug scabug added this to the 2.11.0-RC1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants