summaryrefslogtreecommitdiff
path: root/src/repl/scala/tools/nsc/interpreter/IMain.scala
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/interpreter/IMain.scala
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/interpreter/IMain.scala')
-rw-r--r--src/repl/scala/tools/nsc/interpreter/IMain.scala25
1 files changed, 16 insertions, 9 deletions
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.