summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-01-27 21:27:22 +0000
committerPaul Phillips <paulp@improving.org>2010-01-27 21:27:22 +0000
commit953fecc029a25c1c0cdd1ce847294bc6f7db8e33 (patch)
tree8cbbd56ece83b72d913e6e36ab47330c56e00829 /src
parenta7ad163b511af4875220149839dcd8bfa6f305bd (diff)
downloadscala-953fecc029a25c1c0cdd1ce847294bc6f7db8e33.tar.gz
scala-953fecc029a25c1c0cdd1ce847294bc6f7db8e33.tar.bz2
scala-953fecc029a25c1c0cdd1ce847294bc6f7db8e33.zip
Some hardening of repl generated code. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 21b12e3b84..144bed8400 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -830,12 +830,13 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
}
lazy val loadedResultObject = loadByName(resultObjectName)
- def extractionValue(): AnyRef = {
+ def extractionValue(): Option[AnyRef] = {
// ensure it has run
extractionObjectRun
// load it and retrieve the value
- loadedResultObject getMethod "scala_repl_value" invoke loadedResultObject
+ try Some(loadedResultObject getMethod "scala_repl_value" invoke loadedResultObject)
+ catch { case _: Exception => None }
}
/** Compile the object file. Returns whether the compilation succeeded.
@@ -988,7 +989,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
}
def extractionValueForIdent(id: String): Option[AnyRef] =
- requestForIdent(id) map (_.extractionValue)
+ requestForIdent(id) flatMap (_.extractionValue)
/** Executes code looking for a manifest of type T.
*/
@@ -1057,7 +1058,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
if (req == null || !req.compile || req.handlers.size != 1)
evalError("Eval error.")
- try req.extractionValue.asInstanceOf[T] catch {
+ try req.extractionValue.get.asInstanceOf[T] catch {
case e: Exception => evalError(e.getMessage)
}
}
@@ -1065,7 +1066,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
def interpretExpr[T: Manifest](code: String): Option[T] = beQuietDuring {
interpret(code) match {
case IR.Success =>
- try Some(prevRequests.last.extractionValue.asInstanceOf[T])
+ try prevRequests.last.extractionValue map (_.asInstanceOf[T])
catch { case e: Exception => println(e) ; None }
case _ => None
}