diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-04-10 11:52:01 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-04-21 13:01:03 +0200 |
commit | ec5eaee3ec27b614c3ffe0496a755623c912cfdd (patch) | |
tree | d08a45df201ee77532b0f9b790315c3a114ffc5c /src/compiler/scala/tools/nsc/typechecker/Infer.scala | |
parent | 190aea9f015280d0f48cc2928515d11eccce4e33 (diff) | |
download | scala-ec5eaee3ec27b614c3ffe0496a755623c912cfdd.tar.gz scala-ec5eaee3ec27b614c3ffe0496a755623c912cfdd.tar.bz2 scala-ec5eaee3ec27b614c3ffe0496a755623c912cfdd.zip |
SI-7345 More refactoring and documentation in Contexts
- Use `firstError match {}` rather than `if (c.hasErrors) c.firstError ..`
- Convert implementation comments to doc comments
- Add new doc comments
- Refactor `Context#make` for better readability.
- Note a few TODOs.
- Roughly delineate the internal structure of Contexts with comments.
- Combine `mode` and `state` methods into `contextMode`.
- Move `isNameInScope` closer to its compadres.
- Improving alignment, tightening access.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Infer.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 8d7830897d..8c87cf51d3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -1531,14 +1531,15 @@ trait Infer extends Checkable { } } + /** @return true if the `expr` evaluates to true within a silent Context that incurs no errors */ @inline private def inSilentMode(context: Context)(expr: => Boolean): Boolean = { - val oldState = context.state + val savedContextMode = context.contextMode context.setBufferErrors() val res = expr - val contextWithErrors = context.hasErrors - context.flushBuffer() - context.restoreState(oldState) - res && !contextWithErrors + val contextHadErrors = context.hasErrors + context.reportBuffer.clearAll() + context.contextMode = savedContextMode + res && !contextHadErrors } // Checks against the name of the parameter and also any @deprecatedName. @@ -1636,7 +1637,7 @@ trait Infer extends Checkable { */ def tryTwice(infer: Boolean => Unit): Unit = { if (context.implicitsEnabled) { - val saved = context.state + val savedContextMode = context.contextMode var fallback = false context.setBufferErrors() // We cache the current buffer because it is impossible to @@ -1650,17 +1651,17 @@ trait Infer extends Checkable { context.withImplicitsDisabled(infer(false)) if (context.hasErrors) { fallback = true - context.restoreState(saved) + context.contextMode = savedContextMode context.flushBuffer() infer(true) } } catch { case ex: CyclicReference => throw ex case ex: TypeError => // recoverable cyclic references - context.restoreState(saved) + context.contextMode = savedContextMode if (!fallback) infer(true) else () } finally { - context.restoreState(saved) + context.contextMode = savedContextMode context.updateBuffer(errorsToRestore) } } |