summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-04-10 12:51:57 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-04-21 13:02:04 +0200
commit510ebeca9e55b27bbe6e6c54bf0ea6ea294ee7be (patch)
tree46ee0b2ebf67722e84ce012489b96f4146629feb /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parentec5eaee3ec27b614c3ffe0496a755623c912cfdd (diff)
downloadscala-510ebeca9e55b27bbe6e6c54bf0ea6ea294ee7be.tar.gz
scala-510ebeca9e55b27bbe6e6c54bf0ea6ea294ee7be.tar.bz2
scala-510ebeca9e55b27bbe6e6c54bf0ea6ea294ee7be.zip
SI-7345 Prefer using a throwaway silent context over buffer flushing.
When we are using a throwaway silent context, we can just let it drift out of scope and over the horizon, rather than ceremoniously flushing its buffers on completion. - Applied to Scaladoc. - Applied to Infer#isApplicableSafe. Less manual error buffer management affords greater opportunity to cleanly express the logic. - Applied to `typerReportAnyContextErrors`. The reasoning for the last case is as follows: - There were only two callers to `typerReportAnyContextErrors`, and they both passed in as `c` a child context of `context`. - That child context must share the error reporting mode and buffer with `context`. - Therefore, extracting an error from `c` and issuing it into `context` is a no-op. Because the error buffer is Set, it was harmless. This part will probably textually conflict with the same change made in SI-7319, but the end results are identical.
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala52
1 files changed, 16 insertions, 36 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 3736380954..5523dfd388 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -489,20 +489,9 @@ trait Typers extends Adaptations with Tags {
res
}
- @inline
- final def typerReportAnyContextErrors[T](c: Context)(f: Typer => T): T = {
- val res = f(newTyper(c))
- 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
+ final def newImplTyper[T](impl: ImplDef, clazz: Symbol): Typer = {
+ val c = context.make(impl.impl, clazz, newScope)
+ newTyper(c)
}
@inline
@@ -701,11 +690,7 @@ trait Typers extends Adaptations with Tags {
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)
- }
- }
+ context1.flushAndIssueWarnings()
SilentResultValue(result)
}
} else {
@@ -1812,9 +1797,7 @@ trait Typers extends Adaptations with Tags {
assert(clazz != NoSymbol, cdef)
reenterTypeParams(cdef.tparams)
val tparams1 = cdef.tparams mapConserve (typedTypeDef)
- val impl1 = typerReportAnyContextErrors(context.make(cdef.impl, clazz, newScope)) {
- _.typedTemplate(cdef.impl, typedParentTypes(cdef.impl))
- }
+ val impl1 = newImplTyper(cdef, clazz).typedTemplate(cdef.impl, typedParentTypes(cdef.impl))
val impl2 = finishMethodSynthesis(impl1, clazz, context)
if (clazz.isTrait && clazz.info.parents.nonEmpty && clazz.info.firstParent.typeSymbol == AnyClass)
checkEphemeral(clazz, impl2.body)
@@ -1855,17 +1838,16 @@ trait Typers extends Adaptations with Tags {
|| !linkedClass.isSerializable
|| clazz.isSerializable
)
- val impl1 = typerReportAnyContextErrors(context.make(mdef.impl, clazz, newScope)) {
- _.typedTemplate(mdef.impl, {
- typedParentTypes(mdef.impl) ++ (
- if (noSerializable) Nil
- else {
- clazz.makeSerializable()
- List(TypeTree(SerializableClass.tpe) setPos clazz.pos.focus)
- }
- )
- })
- }
+ val impl1 = newImplTyper(mdef, clazz).typedTemplate(mdef.impl, {
+ typedParentTypes(mdef.impl) ++ (
+ if (noSerializable) Nil
+ else {
+ clazz.makeSerializable()
+ List(TypeTree(SerializableClass.tpe) setPos clazz.pos.focus)
+ }
+ )
+ })
+
val impl2 = finishMethodSynthesis(impl1, clazz, context)
// SI-5954. On second compile of a companion class contained in a package object we end up
@@ -4360,11 +4342,9 @@ trait Typers extends Adaptations with Tags {
case ex: CyclicReference =>
throw ex
case te: TypeError =>
- // @H some of typer erros can still leak,
+ // @H some of typer errors can still leak,
// for instance in continuations
None
- } finally {
- c.flushBuffer()
}
}