summaryrefslogtreecommitdiff
path: root/src/repl/scala/tools/nsc
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2016-05-23 10:12:41 -0700
committerSom Snytt <som.snytt@gmail.com>2016-05-23 22:55:54 -0700
commit5450ae6102eaeb8ec0f9b524bf43ac5f604b5074 (patch)
tree6742327c6184008a885b6cfb98cf96b21e597033 /src/repl/scala/tools/nsc
parent869df338617f2210217827c83d3ef9dc6d810e65 (diff)
downloadscala-5450ae6102eaeb8ec0f9b524bf43ac5f604b5074.tar.gz
scala-5450ae6102eaeb8ec0f9b524bf43ac5f604b5074.tar.bz2
scala-5450ae6102eaeb8ec0f9b524bf43ac5f604b5074.zip
SI-7898 Report paste errors improvedly
Use a "label" for errors, so that script names are shown. Position is still wrong for scripts in REPL. Initial scripts are run with `ILoop.echo` and results printing turned off, but reporter still enabled.
Diffstat (limited to 'src/repl/scala/tools/nsc')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/ILoop.scala20
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala25
2 files changed, 27 insertions, 18 deletions
diff --git a/src/repl/scala/tools/nsc/interpreter/ILoop.scala b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
index 4e0f60cf2b..7dab371caf 100644
--- a/src/repl/scala/tools/nsc/interpreter/ILoop.scala
+++ b/src/repl/scala/tools/nsc/interpreter/ILoop.scala
@@ -1,5 +1,5 @@
/* NSC -- new Scala compiler
- * Copyright 2005-2015 LAMP/EPFL
+ * Copyright 2005-2016 LAMP/EPFL
* @author Alexander Spoon
*/
package scala
@@ -15,7 +15,7 @@ import scala.tools.asm.ClassReader
import scala.util.Properties.{ jdkHome, javaVersion, versionString, javaVmName }
import scala.tools.nsc.util.{ ClassPath, Exceptional, stringFromWriter, stringFromStream }
import scala.reflect.classTag
-import scala.reflect.internal.util.{ BatchSourceFile, ScalaClassLoader }
+import scala.reflect.internal.util.{ BatchSourceFile, ScalaClassLoader, NoPosition }
import ScalaClassLoader._
import scala.reflect.io.{ File, Directory }
import scala.tools.util._
@@ -181,9 +181,9 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
out.flush()
}
// turn off intp reporter and our echo
- def mumly[A](op: =>A): A =
+ def mumly[A](op: => A): A =
if (isReplDebug) op
- else intp beSilentDuring {
+ else intp beQuietDuring {
val saved = mum
mum = true
try op finally mum = saved
@@ -576,9 +576,9 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
}
- def withFile[A](filename: String)(action: File => A): Option[A] = {
+ def withFile[A](filename: String)(action: File => A): Option[A] = intp.withLabel(filename) {
val res = Some(File(filename)) filter (_.exists) map action
- if (res.isEmpty) echo("That file does not exist") // courtesy side-effect
+ if (res.isEmpty) intp.reporter.warning(NoPosition, s"File `$filename' does not exist.") // courtesy side-effect
res
}
@@ -715,6 +715,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
*/
def pasteCommand(arg: String): Result = {
var shouldReplay: Option[String] = None
+ var label = "<pastie>"
def result = Result(keepRunning = true, shouldReplay)
val (raw, file, margin) =
if (arg.isEmpty) (false, None, None)
@@ -735,6 +736,7 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
}
val code = (file, margin) match {
case (Some(name), None) =>
+ label = name
withFile(name) { f =>
shouldReplay = Some(s":paste $arg")
val s = f.slurp.trim
@@ -757,17 +759,17 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
text
}
def interpretCode() = {
- val res = intp interpret code
+ val res = intp.withLabel(label)(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}")
+ val errless = intp compileSources new BatchSourceFile(label, s"object pastel {\n$code\n}")
if (errless) echo("...but compilation found no error? Good luck with that.")
}
}
def compileCode() = {
- val errless = intp compileSources new BatchSourceFile("<pastie>", code)
+ val errless = intp compileSources new BatchSourceFile(label, code)
if (!errless) echo("There were compilation errors!")
}
if (code.nonEmpty) {
diff --git a/src/repl/scala/tools/nsc/interpreter/IMain.scala b/src/repl/scala/tools/nsc/interpreter/IMain.scala
index ef6ab4063a..1e7a9cefed 100644
--- a/src/repl/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/repl/scala/tools/nsc/interpreter/IMain.scala
@@ -1,5 +1,5 @@
/* NSC -- new Scala compiler
- * Copyright 2005-2013 LAMP/EPFL
+ * Copyright 2005-2016 LAMP/EPFL
* @author Martin Odersky
*/
@@ -74,13 +74,14 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
lazy val isClassBased: Boolean = settings.Yreplclassbased.value
- private[nsc] var printResults = true // whether to print result lines
- private[nsc] var totalSilence = false // whether to print anything
- private var _initializeComplete = false // compiler is initialized
- private var _isInitialized: Future[Boolean] = null // set up initialization future
- private var bindExceptions = true // whether to bind the lastException variable
- private var _executionWrapper = "" // code to be wrapped around all lines
- var partialInput: String = "" // code accumulated in multi-line REPL input
+ private[nsc] var printResults = true // whether to print result lines
+ private[nsc] var totalSilence = false // whether to print anything
+ private var _initializeComplete = false // compiler is initialized
+ private var _isInitialized: Future[Boolean] = null // set up initialization future
+ private var bindExceptions = true // whether to bind the lastException variable
+ private var _executionWrapper = "" // code to be wrapped around all lines
+ var partialInput: String = "" // code accumulated in multi-line REPL input
+ private var label = "<console>" // compilation unit name for reporting
/** We're going to go to some trouble to initialize the compiler asynchronously.
* It's critical that nothing call into it until it's been initialized or we will
@@ -108,6 +109,12 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
try body
finally if (!saved) settings.nowarn.value = false
}
+ // Apply a temporary label for compilation (for example, script name)
+ def withLabel[A](temp: String)(body: => A): A = {
+ val saved = label
+ label = temp
+ try body finally label = saved
+ }
/** construct an interpreter that reports to Console */
def this(settings: Settings, out: JPrintWriter) = this(null, settings, out)
@@ -810,7 +817,7 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
case Right(result) => Right(result)
}
- def compile(source: String): Boolean = compileAndSaveRun("<console>", source)
+ def compile(source: String): Boolean = compileAndSaveRun(label, source)
/** The innermost object inside the wrapper, found by
* following accessPath into the outer one.