diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-17 12:47:40 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-07-18 15:49:19 +0200 |
commit | 9707e1df533dd678531c653f5ddedda59df5ce9c (patch) | |
tree | 2922906b102f0d386f26d9310223b14d1a2c7a40 /src | |
parent | 258d95c7b1528a84514a6a609a356be840322e9b (diff) | |
download | scala-9707e1df533dd678531c653f5ddedda59df5ce9c.tar.gz scala-9707e1df533dd678531c653f5ddedda59df5ce9c.tar.bz2 scala-9707e1df533dd678531c653f5ddedda59df5ce9c.zip |
s/reportBuffer/reporter
Diffstat (limited to 'src')
5 files changed, 65 insertions, 66 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 06375d404b..1d4e2c8546 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -128,7 +128,7 @@ trait Contexts { self: Analyzer => case Import(qual, _) => qual setType singleType(qual.symbol.owner.thisType, qual.symbol) case _ => } - context.reportBuffer.clearAll() + context.reporter.clearAll() } } @@ -324,14 +324,13 @@ trait Contexts { self: Analyzer => // Error reporting policies and buffer. // - // TODO: start out with a regular reporter? - private var _reportBuffer: ContextReporter = new ThrowingReporter + private var _reporter: ContextReporter = new ThrowingReporter // the reporter for this context - def reportBuffer = _reportBuffer + def reporter = _reporter // if set, errors will not be reporter/thrown - def bufferErrors = reportBuffer.isBuffering + def bufferErrors = reporter.isBuffering def reportErrors = !bufferErrors // whether to *report* (which is separate from buffering/throwing) ambiguity errors @@ -349,9 +348,9 @@ trait Contexts { self: Analyzer => def apply(): Unit = if (implicitsEnabled) { val savedContextMode = contextMode - val savedReporter = _reportBuffer + val savedReporter = _reporter var fallback = false - _reportBuffer = (new BufferingReporter).sharingBuffersWith(reportBuffer) + _reporter = (new BufferingReporter).sharingBuffersWith(reporter) setAmbiguousErrors(false) // We cache the current buffer because it is impossible to // distinguish errors that occurred before entering tryTwice @@ -359,27 +358,27 @@ trait Contexts { self: Analyzer => // first attempt fails we try with implicits on *and* clean // buffer but that would also flush any pre-tryTwice valid // errors, hence some manual buffer tweaking is necessary. - val errorsToRestore = reportBuffer.errors - reportBuffer.clearAllErrors() + val errorsToRestore = reporter.errors + reporter.clearAllErrors() try { withImplicitsDisabled(tryOnce(false)) - if (reportBuffer.hasErrors) { + if (reporter.hasErrors) { fallback = true contextMode = savedContextMode - _reportBuffer = savedReporter - reportBuffer.clearAllErrors() + _reporter = savedReporter + reporter.clearAllErrors() tryOnce(true) } } catch { case ex: CyclicReference => throw ex case ex: TypeError => // recoverable cyclic references contextMode = savedContextMode - _reportBuffer = savedReporter + _reporter = savedReporter if (!fallback) tryOnce(true) else () } finally { contextMode = savedContextMode - _reportBuffer = savedReporter - reportBuffer ++= errorsToRestore + _reporter = savedReporter + reporter ++= errorsToRestore } } else tryOnce(true) @@ -425,14 +424,14 @@ trait Contexts { self: Analyzer => /** @return true if the `expr` evaluates to true within a silent Context that incurs no errors */ @inline final def inSilentMode(expr: => Boolean): Boolean = { - val savedReporter = _reportBuffer + val savedReporter = _reporter withMode() { // TODO: rework -- withMode with no arguments to restore the mode mutated by `setBufferErrors` (no longer mutated!) - _reportBuffer = (new BufferingReporter).sharingBuffersWith(reportBuffer) + _reporter = (new BufferingReporter).sharingBuffersWith(reporter) setAmbiguousErrors(false) - try expr && !reportBuffer.hasErrors + try expr && !reporter.hasErrors finally { - _reportBuffer = savedReporter - _reportBuffer.clearAll() // TODO: ??? + _reporter = savedReporter + _reporter.clearAll() // TODO: ??? } } } @@ -481,7 +480,7 @@ trait Contexts { self: Analyzer => c.diagUsedDefaults = diagUsedDefaults c.openImplicits = openImplicits c.contextMode = contextMode // note: ConstructorSuffix, a bit within `mode`, is conditionally overwritten below. - c._reportBuffer = _reportBuffer + c._reporter = reporter // Fields that may take on a different value in the child c.prefix = prefixInChild @@ -498,7 +497,7 @@ trait Contexts { self: Analyzer => /** Use reporter (possibly buffered) for errors/warnings and enable implicit conversion **/ def initRootContext(throwing: Boolean = false, checking: Boolean = false): Unit = { - _reportBuffer = + _reporter = if (checking) new CheckingReporter else if (throwing) new ThrowingReporter else new ContextReporter // TODO: this is likely redundant @@ -523,13 +522,13 @@ trait Contexts { self: Analyzer => val c = make(newtree) c.setAmbiguousErrors(reportAmbiguousErrors) // A fresh buffer so as not to leak errors/warnings into `this`. - c._reportBuffer = new BufferingReporter + c._reporter = new BufferingReporter c } def makeNonSilent(newtree: Tree): Context = { val c = make(newtree) - c._reportBuffer = (new ContextReporter).sharingBuffersWith(reportBuffer) + c._reporter = (new ContextReporter).sharingBuffersWith(reporter) c.setAmbiguousErrors(true) c } @@ -555,7 +554,7 @@ trait Contexts { self: Analyzer => val baseContext = enclClass.outer.nextEnclosing(!_.tree.isInstanceOf[Template]) val argContext = baseContext.makeNewScope(tree, owner) argContext.contextMode = contextMode - argContext._reportBuffer = _reportBuffer // caught by neg/t3649 TODO: make sure _reportBuffer is propagated wherever contextMode is + argContext._reporter = _reporter // caught by neg/t3649 TODO: make sure _reporter is propagated wherever contextMode is argContext.inSelfSuperCall = true def enterElems(c: Context) { def enterLocalElems(e: ScopeEntry) { @@ -580,14 +579,14 @@ trait Contexts { self: Analyzer => // /** Issue/buffer/throw the given type error according to the current mode for error reporting. */ - private[typechecker] def issue(err: AbsTypeError) = reportBuffer.issue(err)(this) + private[typechecker] def issue(err: AbsTypeError) = reporter.issue(err)(this) /** Issue/buffer/throw the given implicit ambiguity error according to the current mode for error reporting. */ - private[typechecker] def issueAmbiguousError(err: AbsAmbiguousTypeError) = reportBuffer.issueAmbiguousError(err)(this) + private[typechecker] def issueAmbiguousError(err: AbsAmbiguousTypeError) = reporter.issueAmbiguousError(err)(this) /** Issue/throw the given error message according to the current mode for error reporting. */ - def error(pos: Position, msg: String) = reportBuffer.error(pos, msg) + def error(pos: Position, msg: String) = reporter.error(pos, msg) /** Issue/throw the given error message according to the current mode for error reporting. */ - def warning(pos: Position, msg: String) = reportBuffer.warning(pos, msg) - def echo(pos: Position, msg: String) = reportBuffer.echo(pos, msg) + def warning(pos: Position, msg: String) = reporter.warning(pos, msg) + def echo(pos: Position, msg: String) = reporter.echo(pos, msg) def deprecationWarning(pos: Position, sym: Symbol, msg: String): Unit = diff --git a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala index 0a5521aff4..e03877dbf9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Implicits.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Implicits.scala @@ -71,12 +71,12 @@ trait Implicits { typingStack.printTyping(tree, "typing implicit: %s %s".format(tree, context.undetparamsString)) val implicitSearchContext = context.makeImplicit(reportAmbiguous) val result = new ImplicitSearch(tree, pt, isView, implicitSearchContext, pos).bestImplicit - if (result.isFailure && saveAmbiguousDivergent && implicitSearchContext.reportBuffer.hasErrors) { - context.reportBuffer ++= (implicitSearchContext.reportBuffer.errors.collect { + if (result.isFailure && saveAmbiguousDivergent && implicitSearchContext.reporter.hasErrors) { + context.reporter ++= (implicitSearchContext.reporter.errors.collect { case dte: DivergentImplicitTypeError => dte case ate: AmbiguousImplicitTypeError => ate }) - debuglog("update buffer: " + implicitSearchContext.reportBuffer.errors) + debuglog("update buffer: " + implicitSearchContext.reporter.errors) } // SI-7944 undetermined type parameters that result from inference within typedImplicit land in // `implicitSearchContext.undetparams`, *not* in `context.undetparams` @@ -99,7 +99,7 @@ trait Implicits { def wrapper(inference: => SearchResult) = wrapper1(inference) val result = wrapper(inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos)) if (result.isFailure && !silent) { - val err = context.reportBuffer.firstError + val err = context.reporter.firstError val errPos = err.map(_.errPos).getOrElse(pos) val errMsg = err.map(_.errMsg).getOrElse("implicit search has failed. to find out the reason, turn on -Xlog-implicits") onError(errPos, errMsg) @@ -635,7 +635,7 @@ trait Implicits { } case _ => fallback } - context.reportBuffer.firstError match { // using match rather than foreach to avoid non local return. + context.reporter.firstError match { // using match rather than foreach to avoid non local return. case Some(err) => log("implicit adapt failed: " + err.errMsg) return fail(err.errMsg) @@ -658,8 +658,8 @@ trait Implicits { } } - if (context.reportBuffer.hasErrors) - fail("hasMatchingSymbol reported error: " + context.reportBuffer.firstError.get.errMsg) + if (context.reporter.hasErrors) + fail("hasMatchingSymbol reported error: " + context.reporter.firstError.get.errMsg) else if (itree3.isErroneous) fail("error typechecking implicit candidate") else if (isLocalToCallsite && !hasMatchingSymbol(itree2)) @@ -677,7 +677,7 @@ trait Implicits { // #2421: check that we correctly instantiated type parameters outside of the implicit tree: checkBounds(itree3, NoPrefix, NoSymbol, undetParams, targs, "inferred ") - context.reportBuffer.firstError match { + context.reporter.firstError match { case Some(err) => return fail("type parameters weren't correctly instantiated outside of the implicit tree: " + err.errMsg) case None => @@ -716,7 +716,7 @@ trait Implicits { case t => t } - context.reportBuffer.firstError match { + context.reporter.firstError match { case Some(err) => fail("typing TypeApply reported errors for the implicit tree: " + err.errMsg) case None => @@ -861,7 +861,7 @@ trait Implicits { // We don't want errors that occur while checking the implicit info // to influence the check of further infos, but we should retain divergent implicit errors // (except for the one we already squirreled away) - context.reportBuffer.retainDivergentErrorsExcept(divergentError.getOrElse(null)) + context.reporter.retainDivergentErrorsExcept(divergentError.getOrElse(null)) } search } @@ -907,7 +907,7 @@ trait Implicits { // the first `DivergentImplicitTypeError` that is being propagated // from a nested implicit search; this one will be // re-issued if this level of the search fails. - DivergentImplicitRecovery(typedFirstPending, firstPending, context.reportBuffer.errors) match { + DivergentImplicitRecovery(typedFirstPending, firstPending, context.reporter.errors) match { case sr if sr.isDivergent => Nil case sr if sr.isFailure => rankImplicits(otherPending, acc) case newBest => @@ -1144,7 +1144,7 @@ trait Implicits { try { val tree1 = typedPos(pos.focus)(arg) - context.reportBuffer.firstError match { + context.reporter.firstError match { case Some(err) => processMacroExpansionError(err.errPos, err.errMsg) case None => new SearchResult(tree1, EmptyTreeTypeSubstituter, Nil) } @@ -1357,8 +1357,8 @@ trait Implicits { if (Statistics.canEnable) Statistics.incCounter(inscopeImplicitHits) } if (result.isFailure) { - val previousErrs = context.reportBuffer.errors - context.reportBuffer.clearAllErrors() + val previousErrs = context.reporter.errors + context.reporter.clearAllErrors() val failstart = if (Statistics.canEnable) Statistics.startTimer(oftypeFailNanos) else null val succstart = if (Statistics.canEnable) Statistics.startTimer(oftypeSucceedNanos) else null @@ -1370,7 +1370,7 @@ trait Implicits { result = searchImplicit(implicitsOfExpectedType, isLocalToCallsite = false) if (result.isFailure) { - context.reportBuffer ++= previousErrs + context.reporter ++= previousErrs if (Statistics.canEnable) Statistics.stopTimer(oftypeFailNanos, failstart) } else { if (Statistics.canEnable) Statistics.stopTimer(oftypeSucceedNanos, succstart) @@ -1427,7 +1427,7 @@ trait Implicits { // thus, start each type var off with a fresh for every typedImplicit resetTVars() // any previous errors should not affect us now - context.reportBuffer.clearAllErrors() + context.reporter.clearAllErrors() val res = typedImplicit(ii, ptChecked = false, isLocalToCallsite) if (res.tree ne EmptyTree) List((res, tvars map (_.constr))) else Nil diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 69ac9ea61e..535aaffbbf 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -779,7 +779,7 @@ trait Infer extends Checkable { def applicableExpectingPt(pt: Type): Boolean = { val silent = context.makeSilent(reportAmbiguousErrors = false) val result = newTyper(silent).infer.isApplicable(undetparams, ftpe, argtpes0, pt) - if (silent.reportBuffer.hasErrors && !pt.isWildcard) + if (silent.reporter.hasErrors && !pt.isWildcard) applicableExpectingPt(WildcardType) // second try else result diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index 66152a6ac2..d6870afb10 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -622,7 +622,7 @@ trait Macros extends MacroRuntimes with Traces with Helpers { // `macroExpandApply` is called from `adapt`, where implicit conversions are disabled // therefore we need to re-enable the conversions back temporarily val result = typer.context.withImplicitsEnabled(typer.typed(tree, mode, pt)) - if (result.isErrorTyped && macroDebugVerbose) println(s"$label has failed: ${typer.context.reportBuffer.errors}") + if (result.isErrorTyped && macroDebugVerbose) println(s"$label has failed: ${typer.context.reporter.errors}") result } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 65dc5148ad..c557af88f2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -155,7 +155,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } else { mkArg = gen.mkNamedArg // don't pass the default argument (if any) here, but start emitting named arguments for the following args if (!param.hasDefault && !paramFailed) { - context.reportBuffer.reportFirstDivergentError(fun, param, paramTp)(context) + context.reporter.reportFirstDivergentError(fun, param, paramTp)(context) paramFailed = true } /* else { @@ -466,20 +466,20 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper @inline final def typerWithLocalContext[T](c: Context)(f: Typer => T): T = { val res = f(newTyper(c)) - val errors = c.reportBuffer.errors + val errors = c.reporter.errors if (errors.nonEmpty) { - c.reportBuffer.clearAllErrors() - context.reportBuffer ++= errors + c.reporter.clearAllErrors() + context.reporter ++= errors } res } @inline final def withSavedContext[T](c: Context)(f: => T) = { - val savedErrors = c.reportBuffer.errors - c.reportBuffer.clearAllErrors() + val savedErrors = c.reporter.errors + c.reporter.clearAllErrors() val res = f - c.reportBuffer ++= savedErrors + c.reporter ++= savedErrors res } @@ -687,23 +687,23 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper context.undetparams = context1.undetparams context.savedTypeBounds = context1.savedTypeBounds context.namedApplyBlockInfo = context1.namedApplyBlockInfo - if (context1.reportBuffer.hasErrors) { + if (context1.reporter.hasErrors) { stopStats() - SilentTypeError(context1.reportBuffer.errors: _*) + SilentTypeError(context1.reporter.errors: _*) } else { // If we have a successful result, emit any warnings it created. - context1.reportBuffer.warnings foreach { + context1.reporter.warnings foreach { case (pos, msg) => reporter.warning(pos, msg) } - context1.reportBuffer.clearAllWarnings() + context1.reporter.clearAllWarnings() SilentResultValue(result) } } else { assert(context.bufferErrors || isPastTyper, "silent mode is not available past typer") withSavedContext(context){ val res = op(this) - val errorsToReport = context.reportBuffer.errors - context.reportBuffer.clearAllErrors() + val errorsToReport = context.reporter.errors + context.reporter.clearAllErrors() if (errorsToReport.isEmpty) SilentResultValue(res) else SilentTypeError(errorsToReport.head) } } @@ -810,14 +810,14 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper } // avoid throwing spurious DivergentImplicit errors - if (context.reportBuffer.hasErrors) + if (context.reporter.hasErrors) setError(tree) else withCondConstrTyper(treeInfo.isSelfOrSuperConstrCall(tree))(typer1 => if (original != EmptyTree && pt != WildcardType) ( typer1 silent { tpr => val withImplicitArgs = tpr.applyImplicitArgs(tree) - if (tpr.context.reportBuffer.hasErrors) tree // silent will wrap it in SilentTypeError anyway + if (tpr.context.reporter.hasErrors) tree // silent will wrap it in SilentTypeError anyway else tpr.typed(withImplicitArgs, mode, pt) } orElse { _ => @@ -1051,7 +1051,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper val silentContext = context.makeImplicit(context.ambiguousErrors) val res = newTyper(silentContext).typed( new ApplyImplicitView(coercion, List(tree)) setPos tree.pos, mode, pt) - silentContext.reportBuffer.firstError match { + silentContext.reporter.firstError match { case Some(err) => context.issue(err) case None => return res } @@ -3223,7 +3223,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper (arg1, arg1.tpe.deconst) }.unzip } - if (context.reportBuffer.hasErrors) + if (context.reporter.hasErrors) setError(tree) else { inferMethodAlternative(fun, undetparams, argTpes, pt) @@ -4324,7 +4324,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper c.retyping = true try { val res = newTyper(c).typedArgs(args, mode) - if (c.reportBuffer.hasErrors) None else Some(res) + if (c.reporter.hasErrors) None else Some(res) } catch { case ex: CyclicReference => throw ex |