summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-04-10 11:52:01 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-04-21 13:01:03 +0200
commitec5eaee3ec27b614c3ffe0496a755623c912cfdd (patch)
treed08a45df201ee77532b0f9b790315c3a114ffc5c /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent190aea9f015280d0f48cc2928515d11eccce4e33 (diff)
downloadscala-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/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala38
1 files changed, 25 insertions, 13 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index f57352b11e..3736380954 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -492,8 +492,16 @@ trait Typers extends Adaptations with Tags {
@inline
final def typerReportAnyContextErrors[T](c: Context)(f: Typer => T): T = {
val res = f(newTyper(c))
- if (c.hasErrors)
- context.issue(c.firstError)
+ c.firstError match {
+ case Some(err) =>
+ context.issue(err)
+ c.reportBuffer.warnings foreach {
+ case (pos, msg) => context.warning(pos, msg)
+ }
+ // Seemingly we should perform `c.reportBuffer.clearAll()` here. But
+ // `context` might share the ReportBuffer with `c`.
+ case None =>
+ }
res
}
@@ -687,17 +695,18 @@ trait Typers extends Adaptations with Tags {
context.undetparams = context1.undetparams
context.savedTypeBounds = context1.savedTypeBounds
context.namedApplyBlockInfo = context1.namedApplyBlockInfo
- if (context1.hasErrors) {
- stopStats()
- SilentTypeError(context1.firstError)
- } else {
- // If we have a successful result, emit any warnings it created.
- if (context1.hasWarnings) {
- context1.flushAndReturnWarningsBuffer() foreach {
- case (pos, msg) => unit.warning(pos, msg)
+ context1.firstError match {
+ case Some(err) =>
+ stopStats()
+ SilentTypeError(err)
+ case None =>
+ // If we have a successful result, emit any warnings it created.
+ if (context1.reportBuffer.hasWarnings) {
+ context1.flushAndReturnWarningsBuffer() foreach {
+ case (pos, msg) => unit.warning(pos, msg)
+ }
}
- }
- SilentResultValue(result)
+ SilentResultValue(result)
}
} else {
assert(context.bufferErrors || isPastTyper, "silent mode is not available past typer")
@@ -1174,7 +1183,10 @@ trait Typers extends Adaptations with Tags {
val silentContext = context.makeImplicit(context.ambiguousErrors)
val res = newTyper(silentContext).typed(
new ApplyImplicitView(coercion, List(tree)) setPos tree.pos, mode, pt)
- if (silentContext.hasErrors) context.issue(silentContext.firstError) else return res
+ silentContext.firstError match {
+ case Some(err) => context.issue(err)
+ case None => return res
+ }
}
}
}