diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-23 23:30:52 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-08-04 17:50:42 +0200 |
commit | 3a4c6db9fe8c06b78f907f182e80e908c653cf89 (patch) | |
tree | 4fbfc797fe026012cd4803bc6af29482b6463bc0 /src/compiler/scala/tools/nsc/typechecker/Typers.scala | |
parent | e131424b45881ac8446235f255c8f637602857ac (diff) | |
download | scala-3a4c6db9fe8c06b78f907f182e80e908c653cf89.tar.gz scala-3a4c6db9fe8c06b78f907f182e80e908c653cf89.tar.bz2 scala-3a4c6db9fe8c06b78f907f182e80e908c653cf89.zip |
Towards more privacy for _reporter.
Move code that manipulates the error buffers / reporters
into combinators in Context/ContextReporter.
Eventually, would like to statically know when we're in silent mode,
and only then use buffering (push buffering code down to BufferingReporter).
Simplify TryTwice; avoid capturing mutable var in closure.
Changed inSilentMode to no longer check `&& !reporter.hasErrors`;
disassembling optimized code showed that this was keeping the inliner
from inlining this method.
Introduce a couple more combinators:
- withFreshErrorBuffer
- propagatingErrorsTo
- propagateImplicitTypeErrorsTo
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 33 |
1 files changed, 7 insertions, 26 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index c557af88f2..8549d3dbbc 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -464,24 +464,8 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper if (cond) typerWithLocalContext(c)(f) else f(this) @inline - final def typerWithLocalContext[T](c: Context)(f: Typer => T): T = { - val res = f(newTyper(c)) - val errors = c.reporter.errors - if (errors.nonEmpty) { - c.reporter.clearAllErrors() - context.reporter ++= errors - } - res - } - - @inline - final def withSavedContext[T](c: Context)(f: => T) = { - val savedErrors = c.reporter.errors - c.reporter.clearAllErrors() - val res = f - c.reporter ++= savedErrors - res - } + final def typerWithLocalContext[T](c: Context)(f: Typer => T): T = + c.reporter.propagatingErrorsTo(context.reporter)(f(newTyper(c))) /** The typer for a label definition. If this is part of a template we * first have to enter the label definition. @@ -692,19 +676,16 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper SilentTypeError(context1.reporter.errors: _*) } else { // If we have a successful result, emit any warnings it created. - context1.reporter.warnings foreach { - case (pos, msg) => reporter.warning(pos, msg) - } - context1.reporter.clearAllWarnings() + context1.reporter.emitWarnings() SilentResultValue(result) } } else { assert(context.bufferErrors || isPastTyper, "silent mode is not available past typer") - withSavedContext(context){ + + context.reporter.withFreshErrorBuffer { val res = op(this) - val errorsToReport = context.reporter.errors - context.reporter.clearAllErrors() - if (errorsToReport.isEmpty) SilentResultValue(res) else SilentTypeError(errorsToReport.head) + if (!context.reporter.hasErrors) SilentResultValue(res) + else SilentTypeError(context.reporter.firstError.get) } } } catch { |