diff options
author | Paul Phillips <paulp@improving.org> | 2013-01-17 08:44:35 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-01-17 08:44:35 -0800 |
commit | c3b4a39e68857ad6c8e20385121d0982f0400357 (patch) | |
tree | 211c2348df9c664b2fa66cac3cf104013a244b8b /src | |
parent | b17980666d23250d70bdd5806370939384127945 (diff) | |
parent | 66fe64f8f72ba7d574e07d3308d72cd3766a5763 (diff) | |
download | scala-c3b4a39e68857ad6c8e20385121d0982f0400357.tar.gz scala-c3b4a39e68857ad6c8e20385121d0982f0400357.tar.bz2 scala-c3b4a39e68857ad6c8e20385121d0982f0400357.zip |
Merge pull request #1854 from pufuwozu/ticket-SI-6923
SI-6923 Context now buffers warnings as well as errors
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 b4c5365516..cbcddba487 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){ |