From c9f5ab031a881812149908491217b531b6e29e06 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 9 Apr 2013 21:47:05 +0200 Subject: SI-7345 Encapsulate warning and error buffers in ReportBuffer. - merge `Context#{buffer, warningBuffer}` into `Context#reportBuffer`. - only expose immutable copies of the error and warnings buffers - Introduce a convenience method, `firstError`. - replace `condBufferFlush` more specific methods to retain or clear errors by error kind. --- .../scala/tools/nsc/typechecker/Implicits.scala | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/compiler/scala/tools/nsc/typechecker/Implicits.scala') diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 85e31347be..f7f6970c14 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -81,8 +81,8 @@ trait Implicits { val implicitSearchContext = context.makeImplicit(reportAmbiguous) val result = new ImplicitSearch(tree, pt, isView, implicitSearchContext, pos).bestImplicit if (saveAmbiguousDivergent && implicitSearchContext.hasErrors) { - context.updateBuffer(implicitSearchContext.errBuffer.filter(err => err.kind == ErrorKinds.Ambiguous || err.kind == ErrorKinds.Divergent)) - debuglog("update buffer: " + implicitSearchContext.errBuffer) + context.updateBuffer(implicitSearchContext.reportBuffer.errors.filter(err => err.kind == ErrorKinds.Ambiguous || err.kind == ErrorKinds.Divergent)) + debuglog("update buffer: " + implicitSearchContext.reportBuffer.errors) } printInference("[infer implicit] inferred " + result) context.undetparams = context.undetparams filterNot result.subst.from.contains @@ -585,8 +585,9 @@ trait Implicits { case _ => fallback } if (context.hasErrors) { - log("implicit adapt failed: " + context.errBuffer.head.errMsg) - return fail(context.errBuffer.head.errMsg) + val err = context.firstError + log("implicit adapt failed: " + err.errMsg) + return fail(err.errMsg) } if (Statistics.canEnable) Statistics.incCounter(typedImplicits) @@ -609,7 +610,7 @@ trait Implicits { } if (context.hasErrors) - fail("hasMatchingSymbol reported error: " + context.errBuffer.head.errMsg) + fail("hasMatchingSymbol reported error: " + context.firstError.errMsg) else if (isLocal && !hasMatchingSymbol(itree1)) fail("candidate implicit %s is shadowed by %s".format( info.sym.fullLocationString, itree1.symbol.fullLocationString)) @@ -633,7 +634,7 @@ trait Implicits { // #2421: check that we correctly instantiated type parameters outside of the implicit tree: checkBounds(itree2, NoPrefix, NoSymbol, undetParams, targs, "inferred ") if (context.hasErrors) - return fail("type parameters weren't correctly instantiated outside of the implicit tree: " + context.errBuffer.head.errMsg) + return fail("type parameters weren't correctly instantiated outside of the implicit tree: " + context.firstError.errMsg) // filter out failures from type inference, don't want to remove them from undetParams! // we must be conservative in leaving type params in undetparams @@ -669,7 +670,7 @@ trait Implicits { } if (context.hasErrors) - fail("typing TypeApply reported errors for the implicit tree: " + context.errBuffer.head.errMsg) + fail("typing TypeApply reported errors for the implicit tree: " + context.firstError.errMsg) else { val result = new SearchResult(itree2, subst) if (Statistics.canEnable) Statistics.incCounter(foundImplicits) @@ -828,7 +829,7 @@ trait Implicits { case sr if sr.isFailure => // We don't want errors that occur during checking implicit info // to influence the check of further infos. - context.condBufferFlush(_.kind != ErrorKinds.Divergent) + context.reportBuffer.retainErrors(ErrorKinds.Divergent) rankImplicits(is, acc) case newBest => best = newBest @@ -1085,7 +1086,10 @@ trait Implicits { try { val tree1 = typedPos(pos.focus)(arg) - if (context.hasErrors) processMacroExpansionError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) + if (context.hasErrors) { + val err = context.firstError + processMacroExpansionError(err.errPos, err.errMsg) + } else new SearchResult(tree1, EmptyTreeTypeSubstituter) } catch { case ex: TypeError => -- cgit v1.2.3