Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SI-7345 Move `inSilentMode` from Infer to Context.

  • Loading branch information...
commit 7ce4de49c62258356cb84593f623e38bcefe7f22 1 parent bba9d3d
@retronym retronym authored
View
13 src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -270,7 +270,7 @@ trait Contexts { self: Analyzer =>
// Temporary mode adjustment
//
- private def withMode[T](enabled: ContextMode = NOmode, disabled: ContextMode = NOmode)(op: => T): T = {
+ @inline def withMode[T](enabled: ContextMode = NOmode, disabled: ContextMode = NOmode)(op: => T): T = {
val saved = contextMode
set(enabled, disabled)
try op
@@ -283,6 +283,15 @@ trait Contexts { self: Analyzer =>
def withMacrosEnabled[T](op: => T): T = withMode(enabled = MacrosEnabled)(op)
def withMacrosDisabled[T](op: => T): T = withMode(disabled = MacrosEnabled)(op)
+ /** @return true if the `expr` evaluates to true within a silent Context that incurs no errors */
+ @inline final def inSilentMode(expr: => Boolean): Boolean = {
+ withMode() { // withMode with no arguments to restore the mode mutated by `setBufferErrors`.
+ setBufferErrors()
+ try expr && !hasErrors
+ finally reportBuffer.clearAll()
+ }
+ }
+
//
// Child Context Creation
//
@@ -358,7 +367,7 @@ trait Contexts { self: Analyzer =>
make(tree, owner, newNestedScope(scope))
/** Make a child context that buffers errors and warnings into a fresh report buffer. */
- def makeSilent(reportAmbiguousErrors: Boolean, newtree: Tree = tree): Context = {
+ def makeSilent(reportAmbiguousErrors: Boolean = ambiguousErrors, newtree: Tree = tree): Context = {
val c = make(newtree)
c.setBufferErrors()
c.setAmbiguousErrors(reportAmbiguousErrors)
View
17 src/compiler/scala/tools/nsc/typechecker/Infer.scala
@@ -1540,17 +1540,6 @@ 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 savedContextMode = context.contextMode
- context.setBufferErrors()
- val res = expr
- val contextHadErrors = context.hasErrors
- context.reportBuffer.clearAll()
- context.contextMode = savedContextMode
- res && !contextHadErrors
- }
-
// Checks against the name of the parameter and also any @deprecatedName.
private def paramMatchesName(param: Symbol, name: Name) =
param.name == name || param.deprecatedParamName.exists(_ == name)
@@ -1619,7 +1608,7 @@ trait Infer extends Checkable {
}
def followType(sym: Symbol) = followApply(pre memberType sym)
def bestForExpectedType(pt: Type, isLastTry: Boolean): Unit = {
- val applicable0 = alts filter (alt => inSilentMode(context)(isApplicable(undetparams, followType(alt), argtpes, pt)))
+ val applicable0 = alts filter (alt => context inSilentMode (isApplicable(undetparams, followType(alt), argtpes, pt)))
val applicable = overloadsToConsiderBySpecificity(applicable0, argtpes, varargsStar)
val ranked = bestAlternatives(applicable)((sym1, sym2) =>
isStrictlyMoreSpecific(followType(sym1), followType(sym2), sym1, sym2)
@@ -1629,8 +1618,8 @@ trait Infer extends Checkable {
case best :: Nil => tree setSymbol best setType (pre memberType best) // success
case Nil if pt eq WildcardType => NoBestMethodAlternativeError(tree, argtpes, pt, isLastTry) // failed
case Nil => bestForExpectedType(WildcardType, isLastTry) // failed, but retry with WildcardType
- }
- }
+ }
+ }
// This potentially makes up to four attempts: tryTwice may execute
// with and without views enabled, and bestForExpectedType will try again
// with pt = WildcardType if it fails with pt != WildcardType.
Please sign in to comment.
Something went wrong with that request. Please try again.