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 eval of class def fails the second time #11376

Open
som-snytt opened this Issue Jan 21, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@som-snytt
Copy link

som-snytt commented Jan 21, 2019

2.12 REPL can't re-eval a compiled script that contains a class definition because it attempts to forward all definitions from the wrapper class.

$ scala
Welcome to Scala 2.12.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_144).
Type in expressions for evaluation. Or try :help.

scala> val s = scala.tools.nsc.interpreter.Scripted()
s: scala.tools.nsc.interpreter.Scripted = scala.tools.nsc.interpreter.Scripted@432f4626

scala> s.eval("class C")
res0: Object = null

scala> val c = s.compile("new C")
c: javax.script.CompiledScript = scala.tools.nsc.interpreter.Scripted$WrappedRequest@1c571162

scala> c.eval()
res1: Object = C@318a81a0

scala> c.eval()
res2: Object = C@b1d7b09

scala> val d = s.compile("class D ; new D")
d: javax.script.CompiledScript = scala.tools.nsc.interpreter.Scripted$WrappedRequest@2f4c83f1

scala> d.eval()
res3: Object = D@78652c15

scala> d.eval()
scala.tools.nsc.interpreter.IMain$ReadEvalPrint$EvalException: Failed to load '$line9.$eval': $line9.$eval
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.evalError(IMain.scala:745)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.load(IMain.scala:749)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.evalClass$lzycompute(IMain.scala:752)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.evalClass(IMain.scala:752)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.evalMethod(IMain.scala:795)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:730)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.callEither(IMain.scala:739)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.evalEither(IMain.scala:754)
  at scala.tools.nsc.interpreter.Scripted$WrappedRequest.$anonfun$evalEither$3(Scripted.scala:208)
  at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
  at scala.Console$.withIn(Console.scala:226)
  at scala.tools.nsc.interpreter.Scripted$WrappedRequest.$anonfun$evalEither$2(Scripted.scala:208)
  at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
  at scala.Console$.withErr(Console.scala:192)
  at scala.tools.nsc.interpreter.Scripted$WrappedRequest.$anonfun$evalEither$1(Scripted.scala:207)
  at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
  at scala.Console$.withOut(Console.scala:163)
  at scala.tools.nsc.interpreter.Scripted$WrappedRequest.evalEither(Scripted.scala:206)
  at scala.tools.nsc.interpreter.Scripted$WrappedRequest.$anonfun$eval$1(Scripted.scala:247)
  at scala.tools.nsc.interpreter.Scripted.withScriptContext(Scripted.scala:124)
  at scala.tools.nsc.interpreter.Scripted$WrappedRequest.eval(Scripted.scala:225)
  at javax.script.CompiledScript.eval(CompiledScript.java:106)
  ... 28 elided
Caused by: java.lang.ClassNotFoundException: $line9.$eval
  at scala.reflect.internal.util.AbstractFileClassLoader.findClass(AbstractFileClassLoader.scala:64)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  at java.lang.Class.forName0(Native Method)
  at java.lang.Class.forName(Class.java:348)
  at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.load(IMain.scala:748)
  ... 48 more

scala> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment