summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-10-18 17:58:04 +0000
committerPaul Phillips <paulp@improving.org>2011-10-18 17:58:04 +0000
commitd6eb989388f648eab0d55f25071f540c8df0d0da (patch)
treed294596017ca48387a33f5cbb0fc719230870578
parentee365acb1752e7d789f32df3322a23526377f736 (diff)
downloadscala-d6eb989388f648eab0d55f25071f540c8df0d0da.tar.gz
scala-d6eb989388f648eab0d55f25071f540c8df0d0da.tar.bz2
scala-d6eb989388f648eab0d55f25071f540c8df0d0da.zip
Fixing valueOfTerm in the repl.
Impressed at the amount of ticket traffic for an unadvertised internal method. All the more reason to work toward that support repl API. Don't worry, it'll come. Closes SI-4899, no review.
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/IMain.scala7
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/Naming.scala9
-rw-r--r--test/files/run/imain.check1
-rw-r--r--test/files/run/imain.scala17
4 files changed, 27 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
index 2a1b3ca0f8..e93d4897ca 100644
--- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
@@ -690,6 +690,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
val readName = sessionNames.read
val evalName = sessionNames.eval
val printName = sessionNames.print
+ val resultName = sessionNames.result
class LineExceptional(ex: Throwable) extends Exceptional(ex) {
private def showReplInternal = isettings.showInternalStackTraces
@@ -755,7 +756,7 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
var evalCaught: Option[Throwable] = None
lazy val evalClass = load(evalPath)
- lazy val evalValue = callEither(evalName) match {
+ lazy val evalValue = callEither(resultName) match {
case Left(ex) => evalCaught = Some(ex) ; None
case Right(result) => Some(result)
}
@@ -881,10 +882,10 @@ class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends
else handlers.last.definesTerm match {
case Some(vname) if typeOf contains vname =>
"""
- |lazy val $result = {
+ |lazy val %s = {
| %s
| %s
- |}""".stripMargin.format(lineRep.printName, fullPath(vname))
+ |}""".stripMargin.format(lineRep.resultName, lineRep.printName, fullPath(vname))
case _ => ""
}
// first line evaluates object to make sure constructor is run
diff --git a/src/compiler/scala/tools/nsc/interpreter/Naming.scala b/src/compiler/scala/tools/nsc/interpreter/Naming.scala
index 89868abfb5..7377953263 100644
--- a/src/compiler/scala/tools/nsc/interpreter/Naming.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/Naming.scala
@@ -45,10 +45,11 @@ trait Naming {
sys.props.getOrElse("scala.repl.naming." + name, default)
// Prefixes used in repl machinery. Default to $line, $read, etc.
- def line = propOr("line")
- def read = propOr("read")
- def eval = propOr("eval")
- def print = propOr("print")
+ def line = propOr("line")
+ def read = propOr("read")
+ def eval = propOr("eval")
+ def print = propOr("print")
+ def result = propOr("result")
// The prefix for unnamed results: by default res0, res1, etc.
def res = propOr("res", "res") // INTERPRETER_VAR_PREFIX
diff --git a/test/files/run/imain.check b/test/files/run/imain.check
new file mode 100644
index 0000000000..76df308f3c
--- /dev/null
+++ b/test/files/run/imain.check
@@ -0,0 +1 @@
+Some(246)
diff --git a/test/files/run/imain.scala b/test/files/run/imain.scala
new file mode 100644
index 0000000000..c164fb53ef
--- /dev/null
+++ b/test/files/run/imain.scala
@@ -0,0 +1,17 @@
+object Test {
+ import scala.tools.nsc._
+ import interpreter._
+ import java.io.PrintWriter
+
+ class NullOutputStream extends OutputStream { def write(b: Int) { } }
+
+ def main(args: Array[String]) {
+ val settings = new Settings
+ settings.classpath.value = System.getProperty("java.class.path")
+
+ val intp = new IMain(settings, new PrintWriter(new NullOutputStream))
+ intp.interpret("def x0 = 123")
+ intp.interpret("val x1 = x0 * 2")
+ println(intp.valueOfTerm("x1"))
+ }
+}