diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-06-24 15:54:10 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-04 15:49:08 +0200 |
commit | 9fc68e19309cef139c4827fbed76952011995e10 (patch) | |
tree | 789f30eb129b93efe74d7a026a005fc4a6c53330 /src | |
parent | b7242013830510776fbb93bbf0e883532133030c (diff) | |
download | scala-9fc68e19309cef139c4827fbed76952011995e10.tar.gz scala-9fc68e19309cef139c4827fbed76952011995e10.tar.bz2 scala-9fc68e19309cef139c4827fbed76952011995e10.zip |
Remove deprecationWarning, currentReporting from Reporting
This moves us a bit closer to the goal of having a single
entry point to reporting.
Must modularize Reporting a bit so it can be used in Variances
(need a reference to `currentRun` in `reflect.internal.Reporting`).
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Reporting.scala | 25 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Reporting.scala | 31 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Variances.scala | 2 | ||||
-rw-r--r-- | src/reflect/scala/reflect/runtime/JavaUniverse.scala | 8 |
5 files changed, 40 insertions, 33 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index a6fa3bf1dc..572e579aca 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -1045,7 +1045,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter) def currentUnit: CompilationUnit = if (currentRun eq null) NoCompilationUnit else currentRun.currentUnit def currentSource: SourceFile = if (currentUnit.exists) currentUnit.source else lastSeenSourceFile def currentFreshNameCreator = currentUnit.fresh - def currentReporting = currentRun.reporting def isGlobalInitialized = ( definitions.isDefinitionsInitialized @@ -1093,7 +1092,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) /** Don't want to introduce new errors trying to report errors, * so swallow exceptions. */ - def supplementTyperState(errorMessage: String): String = try { + override def supplementTyperState(errorMessage: String): String = try { val tree = analyzer.lastTreeToTyper val sym = tree.symbol val tpe = tree.tpe @@ -1156,7 +1155,7 @@ class Global(var currentSettings: Settings, var reporter: Reporter) /** A Run is a single execution of the compiler on a set of units. */ - class Run extends RunContextApi { + class Run extends RunContextApi with RunReporting { /** Have been running into too many init order issues with Run * during erroneous conditions. Moved all these vals up to the * top of the file so at least they're not trivially null. @@ -1165,8 +1164,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter) /** The currently compiled unit; set from GlobalPhase */ var currentUnit: CompilationUnit = NoCompilationUnit - val reporting = new PerRunReporting - // used in sbt def uncheckedWarnings: List[(Position, String)] = reporting.uncheckedWarnings // used in sbt diff --git a/src/compiler/scala/tools/nsc/Reporting.scala b/src/compiler/scala/tools/nsc/Reporting.scala index 1b5a778235..9a20807145 100644 --- a/src/compiler/scala/tools/nsc/Reporting.scala +++ b/src/compiler/scala/tools/nsc/Reporting.scala @@ -18,24 +18,13 @@ import scala.collection.{ mutable, immutable } trait Reporting extends scala.reflect.internal.Reporting { self: ast.Positions with CompilationUnits with scala.reflect.api.Symbols => def settings: Settings - // == currentRun.reporting - def currentReporting: PerRunReporting - - def supplementTyperState(errorMessage: String): String - // not deprecated yet, but a method called "error" imported into // nearly every trait really must go. For now using globalError. def error(msg: String) = globalError(msg) - override def deprecationWarning(pos: Position, msg: String) = currentReporting.deprecationWarning(pos, msg) - override def supplementErrorMessage(errorMessage: String) = currentReporting.supplementErrorMessage(errorMessage) - - // a new instance of this class is created for every Run (access the current instance via `currentReporting`) - class PerRunReporting { - // NOTE: scala.reflect.macros.Parsers#parse relies on everything related to reporting going through this def... - // TODO: can we rework this to avoid the indirection/fragility? - def reporter = Reporting.this.reporter - + // a new instance of this class is created for every Run (access the current instance via `currentRun.reporting`) + protected def PerRunReporting = new PerRunReporting + class PerRunReporting extends PerRunReportingBase { /** Collects for certain classes of warnings during this run. */ private class ConditionalWarning(what: String, option: Settings#BooleanSetting) { val warnings = mutable.LinkedHashMap[Position, String]() @@ -126,13 +115,5 @@ trait Reporting extends scala.reflect.internal.Reporting { self: ast.Positions w if (incompleteHandled) incompleteHandler(pos, msg) else reporter.error(pos, msg) - /** Have we already supplemented the error message of a compiler crash? */ - private[this] var supplementedError = false - def supplementErrorMessage(errorMessage: String): String = - if (supplementedError) errorMessage - else { - supplementedError = true - supplementTyperState(errorMessage) - } } }
\ No newline at end of file diff --git a/src/reflect/scala/reflect/internal/Reporting.scala b/src/reflect/scala/reflect/internal/Reporting.scala index 0670e9bd8e..423127803e 100644 --- a/src/reflect/scala/reflect/internal/Reporting.scala +++ b/src/reflect/scala/reflect/internal/Reporting.scala @@ -16,6 +16,32 @@ package internal */ trait Reporting { self : Positions => def reporter: Reporter + def currentRun: RunReporting + + trait RunReporting { + val reporting: PerRunReporting = PerRunReporting + } + + type PerRunReporting <: PerRunReportingBase + protected def PerRunReporting: PerRunReporting + abstract class PerRunReportingBase { + def deprecationWarning(pos: Position, msg: String): Unit + + /** Have we already supplemented the error message of a compiler crash? */ + private[this] var supplementedError = false + def supplementErrorMessage(errorMessage: String): String = + if (supplementedError) errorMessage + else { + supplementedError = true + supplementTyperState(errorMessage) + } + + } + + // overridden in Global + def supplementTyperState(errorMessage: String): String = errorMessage + + def supplementErrorMessage(errorMessage: String) = currentRun.reporting.supplementErrorMessage(errorMessage) @deprecatedOverriding("This forwards to the corresponding method in reporter -- override reporter instead", "2.11.2") def inform(msg: String): Unit = inform(NoPosition, msg) @@ -39,11 +65,6 @@ trait Reporting { self : Positions => def warning(pos: Position, msg: String) = reporter.warning(pos, msg) @deprecatedOverriding("This forwards to the corresponding method in reporter -- override reporter instead", "2.11.2") def globalError(pos: Position, msg: String) = reporter.error(pos, msg) - - def deprecationWarning(pos: Position, msg: String): Unit = warning(msg) - - /** Overridden when we know more about what was happening during a failure. */ - def supplementErrorMessage(msg: String): String = msg } import util.Position diff --git a/src/reflect/scala/reflect/internal/Variances.scala b/src/reflect/scala/reflect/internal/Variances.scala index cfe2ad8b87..12b765b7a6 100644 --- a/src/reflect/scala/reflect/internal/Variances.scala +++ b/src/reflect/scala/reflect/internal/Variances.scala @@ -79,7 +79,7 @@ trait Variances { // Unsound pre-2.11 behavior preserved under -Xsource:2.10 if (settings.isScala211 || sym.isOverridingSymbol) Invariant else { - deprecationWarning(sym.pos, s"Construct depends on unsound variance analysis and will not compile in scala 2.11 and beyond") + currentRun.reporting.deprecationWarning(sym.pos, s"Construct depends on unsound variance analysis and will not compile in scala 2.11 and beyond") Bivariant } ) diff --git a/src/reflect/scala/reflect/runtime/JavaUniverse.scala b/src/reflect/scala/reflect/runtime/JavaUniverse.scala index d846ef2cdd..fe39e1f245 100644 --- a/src/reflect/scala/reflect/runtime/JavaUniverse.scala +++ b/src/reflect/scala/reflect/runtime/JavaUniverse.scala @@ -27,6 +27,14 @@ class JavaUniverse extends InternalSymbolTable with JavaUniverseForce with Refle protected def info0(pos: Position, msg: String, severity: Severity, force: Boolean): Unit = log(msg) } + // minimal Run to get Reporting wired + def currentRun = new RunReporting {} + class PerRunReporting extends PerRunReportingBase { + def deprecationWarning(pos: Position, msg: String): Unit = reporter.warning(pos, msg) + } + protected def PerRunReporting = new PerRunReporting + + type TreeCopier = InternalTreeCopierOps implicit val TreeCopierTag: ClassTag[TreeCopier] = ClassTag[TreeCopier](classOf[TreeCopier]) def newStrictTreeCopier: TreeCopier = new StrictTreeCopier |