summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2014-07-09 17:15:40 +0200
committerAdriaan Moors <adriaan.moors@typesafe.com>2014-07-17 15:52:43 +0200
commitc6bee6437a626c93be3951ee0437adce8c88e96c (patch)
tree4545d062f57256eebf7d1c0db88ed3a64698ccbd /src/compiler/scala/tools/nsc/typechecker/Contexts.scala
parent5e62c59aad9dabb3b07e2330d2f8b937f48b93e8 (diff)
downloadscala-c6bee6437a626c93be3951ee0437adce8c88e96c.tar.gz
scala-c6bee6437a626c93be3951ee0437adce8c88e96c.tar.bz2
scala-c6bee6437a626c93be3951ee0437adce8c88e96c.zip
Untangle reporting of ambiguous errors.
Now that all reporting mode manipulators are private to Context, let's untangle this logic: - every `setReportErrors` gets a corresponding `setAmbiguousErrors(true)` - every `setBufferErrors` gets a corresponding `setAmbiguousErrors(false)` - every `setThrowErrors` gets a corresponding `setAmbiguousErrors(false)` `ambiguousErrors` means that ambiguity errors *must* be reported, even when in silent mode. When it's false, they are *not* reported, but they are buffered when the context reporter is buffering. TODO: this seems a bit dubious, but this is what happens now. Let's see if we can simplify this once the refactoring is complete. Again, the end goal is a strategy-based approach to reporting, where the reporting mode is captured in the reporter being used, with as little mutation as possible to capture more invariants (would like to stop throwing TypeError eventually and only have two reporters: buffering reporter, regular reporter)
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Contexts.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 8b53e8eeac..f5f9494562 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -317,7 +317,7 @@ trait Contexts { self: Analyzer =>
*/
def savingUndeterminedTypeParams[A](reportAmbiguous: Boolean = ambiguousErrors)(body: => A): A = {
withMode() {
- this(AmbiguousErrors) = reportAmbiguous
+ setAmbiguousErrors(reportAmbiguous)
val saved = extractUndetparams()
try body
finally undetparams = saved
@@ -337,9 +337,9 @@ trait Contexts { self: Analyzer =>
def ambiguousErrors = this(AmbiguousErrors)
private def throwErrors = contextMode.inNone(ReportErrors | BufferErrors)
- private def setReportErrors(): Unit = set(enable = ReportErrors | AmbiguousErrors, disable = BufferErrors)
- private def setBufferErrors(): Unit = set(enable = BufferErrors, disable = ReportErrors | AmbiguousErrors)
- private def setThrowErrors(): Unit = this(ReportErrors | AmbiguousErrors | BufferErrors) = false
+ private def setReportErrors(): Unit = set(enable = ReportErrors, disable = BufferErrors)
+ private def setBufferErrors(): Unit = set(enable = BufferErrors, disable = ReportErrors)
+ private def setThrowErrors(): Unit = this(ReportErrors | BufferErrors) = false
private def setAmbiguousErrors(report: Boolean): Unit = this(AmbiguousErrors) = report
@@ -354,6 +354,7 @@ trait Contexts { self: Analyzer =>
val savedContextMode = contextMode
var fallback = false
setBufferErrors()
+ setAmbiguousErrors(false)
// We cache the current buffer because it is impossible to
// distinguish errors that occurred before entering tryTwice
// and our first attempt in 'withImplicitsDisabled'. If the
@@ -425,6 +426,7 @@ trait Contexts { self: Analyzer =>
@inline final def inSilentMode(expr: => Boolean): Boolean = {
withMode() { // withMode with no arguments to restore the mode mutated by `setBufferErrors`.
setBufferErrors()
+ setAmbiguousErrors(false)
try expr && !reportBuffer.hasErrors
finally reportBuffer.clearAll()
}
@@ -492,6 +494,7 @@ trait Contexts { self: Analyzer =>
/** Use reporter (possibly buffered) for errors/warnings and enable implicit conversion **/
def initRootContext(): Unit = {
setReportErrors()
+ setAmbiguousErrors(true)
this(EnrichmentEnabled | ImplicitsEnabled) = true
}
@@ -500,6 +503,7 @@ trait Contexts { self: Analyzer =>
*/
def initRootContextPostTyper(): Unit = {
setThrowErrors()
+ setAmbiguousErrors(false)
this(EnrichmentEnabled | ImplicitsEnabled) = false
}
@@ -525,6 +529,7 @@ trait Contexts { self: Analyzer =>
def makeNonSilent(newtree: Tree): Context = {
val c = make(newtree)
c.setReportErrors()
+ c.setAmbiguousErrors(true)
c
}