summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/interpreter/IMain.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-08-09 17:35:29 +0000
committerPaul Phillips <paulp@improving.org>2011-08-09 17:35:29 +0000
commitc1aaf1fc7ad3d76bb5376d796577e0effdd70bf4 (patch)
treed89ddcb0f6b241b9cf1560b538e703cf1760d12e /src/compiler/scala/tools/nsc/interpreter/IMain.scala
parent554fb11b0cd2f76d7990a0de935c8deef30f95dc (diff)
downloadscala-c1aaf1fc7ad3d76bb5376d796577e0effdd70bf4.tar.gz
scala-c1aaf1fc7ad3d76bb5376d796577e0effdd70bf4.tar.bz2
scala-c1aaf1fc7ad3d76bb5376d796577e0effdd70bf4.zip
Don't discard deprecation/unchecked warnings re...
Don't discard deprecation/unchecked warnings regardless of settings. Changed warnings code to accumulate them rather than thoughtlessly discarding them and issuing its well-known taunt. In the repl you can take advantage of this with the :warnings command, which will show the suppressed warnings from the last line which had any. Be advised that at the moment it has some issues: unchecked warnings aren't making it out, and near repl startup neither are deprecation warnings, so don't open a bunch of tickets please. References SI-4594, no review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/interpreter/IMain.scala')
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/IMain.scala89
1 files changed, 75 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/interpreter/IMain.scala b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
index 3abcb3e416..b516e137e8 100644
--- a/src/compiler/scala/tools/nsc/interpreter/IMain.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/IMain.scala
@@ -60,9 +60,33 @@ import IMain._
* @author Moez A. Abdel-Gawad
* @author Lex Spoon
*/
-class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imports {
+class IMain(initialSettings: Settings, protected val out: JPrintWriter) extends Imports {
imain =>
+ private var currentSettings: Settings = initialSettings
+ def settings = currentSettings
+ def savingSettings[T](fn: Settings => Unit)(body: => T): T = {
+ val saved = currentSettings
+ currentSettings = saved.copy()
+ fn(currentSettings)
+ try body
+ finally currentSettings = saved
+ }
+ def mostRecentLine = prevRequestList match {
+ case Nil => ""
+ case req :: _ => req.originalLine
+ }
+ def rerunWith(names: String*) = {
+ savingSettings((ss: Settings) => {
+ import ss._
+ names flatMap lookupSetting foreach {
+ case s: BooleanSetting => s.value = true
+ case _ => ()
+ }
+ })(interpret(mostRecentLine))
+ }
+ def rerunForWarnings = rerunWith("-deprecation", "-unchecked", "-Xlint")
+
/** construct an interpreter that reports to Console */
def this(settings: Settings) = this(settings, new NewLinePrintWriter(new ConsoleWriter, true))
def this() = this(new Settings())
@@ -408,14 +432,18 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
}
}
+ def compileSourcesKeepingRun(sources: SourceFile*) = {
+ val run = new Run()
+ reporter.reset()
+ run compileSources sources.toList
+ (!reporter.hasErrors, run)
+ }
+
/** Compile an nsc SourceFile. Returns true if there are
* no compilation errors, or false otherwise.
*/
- def compileSources(sources: SourceFile*): Boolean = {
- reporter.reset()
- new Run() compileSources sources.toList
- !reporter.hasErrors
- }
+ def compileSources(sources: SourceFile*): Boolean =
+ compileSourcesKeepingRun(sources: _*)._1
/** Compile a string. Returns true if there are no
* compilation errors, or false otherwise.
@@ -461,9 +489,11 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
case Some(trees) => trees
}
repltrace(
- trees map { t =>
- t map { t0 => t0.getClass + " at " + safePos(t0, -1) + "\n" }
- } mkString
+ trees map (t =>
+ t map (t0 =>
+ " " + safePos(t0, -1) + ": " + t0.shortClass + "\n"
+ ) mkString ""
+ ) mkString "\n"
)
// If the last tree is a bare expression, pinpoint where it begins using the
// AST node position and snap the line off there. Rewrite the code embodied
@@ -747,6 +777,29 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
lineAfterTyper(sym.info member newTermName(name))
}
}
+ /** We get a bunch of repeated warnings for reasons I haven't
+ * entirely figured out yet. For now, squash.
+ */
+ private def removeDupWarnings(xs: List[(Position, String)]): List[(Position, String)] = {
+ if (xs.isEmpty)
+ return Nil
+
+ val ((pos, msg)) :: rest = xs
+ val filtered = rest filter { case (pos0, msg0) =>
+ (msg != msg0) || (pos.lineContent.trim != pos0.lineContent.trim) || {
+ // same messages and same line content after whitespace removal
+ // but we want to let through multiple warnings on the same line
+ // from the same run. The untrimmed line will be the same since
+ // there's no whitespace indenting blowing it.
+ (pos.lineContent == pos0.lineContent)
+ }
+ }
+ ((pos, msg)) :: removeDupWarnings(filtered)
+ }
+ def lastWarnings: List[(Position, String)] = (
+ if (lastRun == null) Nil
+ else removeDupWarnings(lastRun.deprecationWarnings.reverse) ++ lastRun.uncheckedWarnings.reverse
+ )
private var lastRun: Run = _
private def evalMethod(name: String) = evalClass.getMethods filter (_.getName == name) match {
case Array(method) => method
@@ -754,10 +807,9 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
}
private def compileAndSaveRun(label: String, code: String) = {
showCodeIfDebugging(code)
- reporter.reset()
- lastRun = new Run()
- lastRun.compileSources(List(new BatchSourceFile(label, packaged(code))))
- !reporter.hasErrors
+ val (success, run) = compileSourcesKeepingRun(new BatchSourceFile(label, packaged(code)))
+ lastRun = run
+ success
}
}
@@ -880,7 +932,9 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
// compile the result-extraction object
beSilentDuring {
- lineRep compile ResultObjectSourceCode(handlers)
+ savingSettings(_.nowarn.value = true) {
+ lineRep compile ResultObjectSourceCode(handlers)
+ }
}
}
}
@@ -949,6 +1003,13 @@ class IMain(val settings: Settings, protected val out: JPrintWriter) extends Imp
case _ => naming.mostRecentVar
})
+ def lastWarnings: List[(global.Position, String)] = (
+ prevRequests.reverseIterator
+ map (_.lineRep.lastWarnings)
+ find (_.nonEmpty)
+ getOrElse Nil
+ )
+
def requestForName(name: Name): Option[Request] = {
assert(definedNameMap != null, "definedNameMap is null")
definedNameMap get name