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
valueOfTerm method of scala.tools.nsc.interpreter.IMain broken in 2.9.1 RC2 #4899
Comments
Imported From: https://issues.scala-lang.org/browse/SI-4899?orig=1 |
Eugene Yokota (eed3si9n) said: |
Sebastien Riou (acapola) said: scala> val n = new scala.tools.nsc.interpreter.IMain() scala> n.interpret("val r=1") scala> n.valueOfTerm("r") How to get the value of r then ??? |
Zach Cox (zcox) said:
The underlying cause of this is that ReadEvalPrint.call throws an exception if you try to access the evaluated value:
IMain.valueOfTerm ultimately calls ReadEvalPrint.callEither which swallows that exception and eventually a None bubbles up and gets returned. I haven't done any more digging as to why that exception is thrown, will report more details if I find them. Are there any known workarounds for this? We're embedding the Scala REPL and trying to customize the Print stage to dump the contents of any eval'ed collection or iterator in Gremlin and this bug is impeding progress. |
Sebastien Riou (acapola) said: |
Wiktor Macura (wmacura) said (edited on Oct 17, 2011 7:27:07 PM UTC): It seems that the problem is that object IMainSpecs extends Specification {
"IMain" should {
"give term value" in {
System.setProperty("settings.usejavacp.value", "true")
val settings = new Settings()
settings.embeddedDefaults[UXPad]
settings.processArgumentString("-usejavacp")
class MyIMain extends IMain(settings) {
def lastRequest = prevRequestList.last
}
val n = new MyIMain()
n.interpret("val a = 1")
val r = n.lastRequest
r.lineRep.call("$result").must_== (1)
}
}
} |
Zach Cox (zcox) said: If I run your code (excluding the UXPad line) in the REPL I end up with null instead of 1:
If I run your Specification using sbt test then I get this exception on the n.interpret() line:
Could you please provide more details about the environment in which that test passes for you? |
Wiktor Macura (wmacura) said (edited on Oct 18, 2011 3:08:17 AM UTC): Yes, sorry. I should have extracted the minimal test case: import tools.nsc.interpreter.IMain
import tools.nsc.Settings
val settings = new Settings()
class MyIMain extends IMain() {
def lastRequest = prevRequestList.last
}
val n = new MyIMain()
n.interpret("val a = 123")
val r = n.lastRequest
println(r.lineRep.call("$result")) Running: [wiktor@wiktorair1 Documents]# scala -version
Scala code runner version 2.9.1.final -- Copyright 2002-2011, LAMP/EPFL
[wiktor@wiktorair1 Documents]# scala Test.scala
a: Int = 123
123 This is on OS X, if it matters. |
Zach Cox (zcox) said: I made it even a bit more minimal:
|
The valueOfTerm method of scala.tools.nsc.interpreter.IMain seems to be broken in 2.9.1 RC2, whereas it works as expected in 2.9.0.1. See transcripts from both versions below.
Welcome to Scala version 2.9.1.RC2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val n = new scala.tools.nsc.interpreter.IMain()
n: scala.tools.nsc.interpreter.IMain = scala.tools.nsc.interpreter.IMain@f4f7a86
scala> n.interpret("val a = 2+3")
a: Int = 5
res0: scala.tools.nsc.interpreter.package.IR.Result = Success
scala> n.valueOfTerm("a") == Some(5) // Should be true!
res1: Boolean = false
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_26).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val n = new scala.tools.nsc.interpreter.IMain()
n: scala.tools.nsc.interpreter.IMain = scala.tools.nsc.interpreter.IMain@34ae19a
scala> n.interpret("val a = 2+3")
a: Int = 5
res0: scala.tools.nsc.interpreter.Results.Result = Success
scala> n.valueOfTerm("a") == Some(5) // Is true, as it should be
res1: Boolean = true
The text was updated successfully, but these errors were encountered: