summaryrefslogtreecommitdiff
path: root/src/repl
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2014-03-15 02:14:01 -0700
committerSom Snytt <som.snytt@gmail.com>2014-03-15 02:14:01 -0700
commit47c03aa5a8fc0d66c28574b6029fa3f150a6a4e9 (patch)
tree26a0a2df861e244a1e0378a75b5b0e478f567e0d /src/repl
parent492624d729730d594097aa618f8f1e34caa79639 (diff)
downloadscala-47c03aa5a8fc0d66c28574b6029fa3f150a6a4e9.tar.gz
scala-47c03aa5a8fc0d66c28574b6029fa3f150a6a4e9.tar.bz2
scala-47c03aa5a8fc0d66c28574b6029fa3f150a6a4e9.zip
SI-8415 Exception handling in REPL init
Incremental robustness, and probe for typer phase. The probe would be unnecessary if repl contributed a terminal phase that "requires" whatever it needs; that is checked when the Run is built.
Diffstat (limited to 'src/repl')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala10
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala7
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ReplGlobal.scala2
3 files changed, 15 insertions, 4 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index a96bed4696..ce0eadc04f 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -402,7 +402,13 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
private val crashRecovery: PartialFunction[Throwable, Boolean] = {
case ex: Throwable =>
- echo(intp.global.throwableAsString(ex))
+ val (err, explain) = (
+ if (intp.isInitializeComplete)
+ (intp.global.throwableAsString(ex), "")
+ else
+ (ex.getMessage, "The compiler did not initialize.\n")
+ )
+ echo(err)
ex match {
case _: NoSuchMethodError | _: NoClassDefFoundError =>
@@ -410,7 +416,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
throw ex
case _ =>
def fn(): Boolean =
- try in.readYesOrNo(replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
+ try in.readYesOrNo(explain + replayQuestionMessage, { echo("\nYou must enter y or n.") ; fn() })
catch { case _: RuntimeException => false }
if (fn()) replay()
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala
index 9c853fb514..47d97dd4dd 100644
--- a/src/repl/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala
@@ -117,8 +117,10 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
private def _initSources = List(new BatchSourceFile("<init>", "class $repl_$init { }"))
private def _initialize() = {
try {
- // todo. if this crashes, REPL will hang
- new _compiler.Run() compileSources _initSources
+ // if this crashes, REPL will hang its head in shame
+ val run = new _compiler.Run()
+ assert(run.typerPhase != NoPhase, "REPL requires a typer phase.")
+ run compileSources _initSources
_initializeComplete = true
true
}
@@ -384,6 +386,7 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
def compileSourcesKeepingRun(sources: SourceFile*) = {
val run = new Run()
+ assert(run.typerPhase != NoPhase, "REPL requires a typer phase.")
reporter.reset()
run compileSources sources.toList
(!reporter.hasErrors, run)
diff --git a/src/repl/scala/tools/nsc/interpreter/ReplGlobal.scala b/src/repl/scala/tools/nsc/interpreter/ReplGlobal.scala
index 51fab3082e..07d619bca5 100644
--- a/src/repl/scala/tools/nsc/interpreter/ReplGlobal.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ReplGlobal.scala
@@ -55,6 +55,8 @@ trait ReplGlobal extends Global {
// newNamer(rootContext(unit)).enterSym(unit.body)
}
}
+ // add to initial or terminal phase to sanity check Run at construction
+ override val requires = List("typer") // ensure they didn't -Ystop-after:parser
}
override protected def computePhaseDescriptors: List[SubComponent] = {