diff options
author | Brian McKenna <brian@precog.com> | 2013-01-07 18:17:05 +1000 |
---|---|---|
committer | Brian McKenna <brian@precog.com> | 2013-01-07 19:22:04 +1000 |
commit | 66fe64f8f72ba7d574e07d3308d72cd3766a5763 (patch) | |
tree | aca5503608b9265e24d73ded3c144cd34ad7e8a0 /src | |
parent | 766bb97114b5932b75340a9169558de61899997e (diff) | |
download | scala-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')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 9 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 10 |
2 files changed, 18 insertions, 1 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 { diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 9d390476db..8722aa3666 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -728,7 +728,15 @@ trait Typers extends Modes with Adaptations with Tags { if (context1.hasErrors) { stopStats() SilentTypeError(context1.errBuffer.head) - } else SilentResultValue(result) + } else { + // If we have a successful result, emit any warnings it created. + if (context1.hasWarnings) { + context1.flushAndReturnWarningsBuffer() foreach { + case (pos, msg) => unit.warning(pos, msg) + } + } + SilentResultValue(result) + } } else { assert(context.bufferErrors || isPastTyper, "silent mode is not available past typer") withSavedContext(context){ |