summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
diff options
context:
space:
mode:
authorBrian McKenna <brian@precog.com>2013-01-07 18:17:05 +1000
committerBrian McKenna <brian@precog.com>2013-01-07 19:22:04 +1000
commit66fe64f8f72ba7d574e07d3308d72cd3766a5763 (patch)
treeaca5503608b9265e24d73ded3c144cd34ad7e8a0 /src/compiler/scala/tools/nsc/typechecker/Contexts.scala
parent766bb97114b5932b75340a9169558de61899997e (diff)
downloadscala-66fe64f8f72ba7d574e07d3308d72cd3766a5763.tar.gz
scala-66fe64f8f72ba7d574e07d3308d72cd3766a5763.tar.bz2
scala-66fe64f8f72ba7d574e07d3308d72cd3766a5763.zip
SI-6923 Context now buffers warnings as well as errors
Code that was silently typed would not report warnings, even if it returned a successful result. This appeared in the following code which didn't show warnings even with -Ywarn-adapted-args: def foo(a: Any) = a; foo(1, 2) While the following would show the expected warning: def foo[A](a: Any) = a; foo(1, 2)
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Contexts.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 0907f1088a..af2aeefecd 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -144,6 +144,7 @@ trait Contexts { self: Analyzer =>
def typingIndent = " " * typingIndentLevel
var buffer: Set[AbsTypeError] = _
+ var warningsBuffer: Set[(Position, String)] = _
def enclClassOrMethod: Context =
if ((owner eq NoSymbol) || (owner.isClass) || (owner.isMethod)) this
@@ -165,6 +166,7 @@ trait Contexts { self: Analyzer =>
def errBuffer = buffer
def hasErrors = buffer.nonEmpty
+ def hasWarnings = warningsBuffer.nonEmpty
def state: Int = mode
def restoreState(state0: Int) = mode = state0
@@ -193,6 +195,11 @@ trait Contexts { self: Analyzer =>
buffer.clear()
current
}
+ def flushAndReturnWarningsBuffer(): Set[(Position, String)] = {
+ val current = warningsBuffer.clone()
+ warningsBuffer.clear()
+ current
+ }
def logError(err: AbsTypeError) = buffer += err
@@ -282,6 +289,7 @@ trait Contexts { self: Analyzer =>
c.retyping = this.retyping
c.openImplicits = this.openImplicits
c.buffer = if (this.buffer == null) LinkedHashSet[AbsTypeError]() else this.buffer // need to initialize
+ c.warningsBuffer = if (this.warningsBuffer == null) LinkedHashSet[(Position, String)]() else this.warningsBuffer
registerContext(c.asInstanceOf[analyzer.Context])
debuglog("[context] ++ " + c.unit + " / " + tree.summaryString)
c
@@ -406,6 +414,7 @@ trait Contexts { self: Analyzer =>
def warning(pos: Position, msg: String): Unit = warning(pos, msg, false)
def warning(pos: Position, msg: String, force: Boolean) {
if (reportErrors || force) unit.warning(pos, msg)
+ else if (bufferErrors) warningsBuffer += ((pos, msg))
}
def isLocal(): Boolean = tree match {