summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-06-25 17:23:50 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-06-25 17:23:50 -0700
commit07fc7bb2f718f335058ea84700778827747a6314 (patch)
tree9421280eb8acad7d3b9187dce8fec2eaf2cd1004
parent807dc9e15fa36cc92a9bd2802dbfbff2de5d0dec (diff)
parent990c2b024a467d22ae65028ba3bad3443108f7f8 (diff)
downloadscala-07fc7bb2f718f335058ea84700778827747a6314.tar.gz
scala-07fc7bb2f718f335058ea84700778827747a6314.tar.bz2
scala-07fc7bb2f718f335058ea84700778827747a6314.zip
Merge pull request #2672 from som-snytt/issue/6855-repl-pasted-brace
SI-6855: REPL emits error on partial pastie
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala16
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.")
+ }
+ }
()
}