diff options
author | Som Snytt <som.snytt@gmail.com> | 2013-06-21 22:34:38 -0700 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2013-06-22 10:37:44 -0700 |
commit | 990c2b024a467d22ae65028ba3bad3443108f7f8 (patch) | |
tree | 5b1b1ac22fddbea69fed64ed77a12d60f8ff6bb6 | |
parent | 0ebdc586ca347b2ced5a26bd0f91203228859b01 (diff) | |
download | scala-990c2b024a467d22ae65028ba3bad3443108f7f8.tar.gz scala-990c2b024a467d22ae65028ba3bad3443108f7f8.tar.bz2 scala-990c2b024a467d22ae65028ba3bad3443108f7f8.zip |
SI-6855: REPL emits error on partial pastie
If pasted code is interpreted with an incomplete result,
attempt to compile it to display an error.
Unfancily, the code is wrapped in an object for compilation.
-rw-r--r-- | src/repl/scala/tools/nsc/interpreter/ILoop.scala | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala index 8ec8b2ed5f..a84d076e76 100644 --- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala +++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala @@ -22,6 +22,7 @@ import scala.reflect.classTag import StdReplTags._ import scala.concurrent.{ ExecutionContext, Await, Future, future } import ExecutionContext.Implicits._ +import scala.reflect.internal.util.BatchSourceFile /** The Scala interactive shell. It provides a read-eval-print loop * around the Interpreter class. @@ -530,8 +531,19 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter) def pasteCommand(): Result = { echo("// Entering paste mode (ctrl-D to finish)\n") val code = readWhile(_ => true) mkString "\n" - echo("\n// Exiting paste mode, now interpreting.\n") - intp interpret code + if (code.trim.isEmpty) { + echo("\n// Nothing pasted, nothing gained.\n") + } else { + echo("\n// Exiting paste mode, now interpreting.\n") + val res = intp interpret code + // if input is incomplete, let the compiler try to say why + if (res == IR.Incomplete) { + echo("The pasted code is incomplete!\n") + // Remembrance of Things Pasted in an object + val errless = intp compileSources new BatchSourceFile("<pastie>", s"object pastel {\n$code\n}") + if (errless) echo("...but compilation found no error? Good luck with that.") + } + } () } |