summaryrefslogtreecommitdiff
path: root/src/compiler
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-04-16 09:18:17 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-04-21 13:05:27 +0200
commit7ce4de49c62258356cb84593f623e38bcefe7f22 (patch)
tree475a86f3000e2ad1f5ba6a3e36f343501ce5ead6 /src/compiler
parentbba9d3d468a4be6a867aa4494375fcc108c8b97e (diff)
downloadscala-7ce4de49c62258356cb84593f623e38bcefe7f22.tar.gz
scala-7ce4de49c62258356cb84593f623e38bcefe7f22.tar.bz2
scala-7ce4de49c62258356cb84593f623e38bcefe7f22.zip
SI-7345 Move `inSilentMode` from Infer to Context.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala13
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Infer.scala17
2 files changed, 14 insertions, 16 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 5bbb96ccd2..fd15d9f675 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/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)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala
index 323ed3287e..1bd17e51d2 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala
+++ b/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.