From dda3f241e7c47d13710be6a7e1ea9d5ef69709b2 Mon Sep 17 00:00:00 2001 From: Adriaan Moors Date: Wed, 9 Jul 2014 18:14:06 +0200 Subject: Rely less on intricacies of `contextMode`-based reporting. - when warning must not be suppressed, use `reporter.warning` - don't (implicitly) rely on `reporter.warning` being silent after typer --> don't do pure expression check after typer --- src/compiler/scala/tools/nsc/typechecker/Contexts.scala | 4 ++-- src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala | 6 +++--- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala index 6951ff2f0b..1010ceafe3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala @@ -640,8 +640,8 @@ trait Contexts { self: Analyzer => } /** Issue/throw the given error message according to the current mode for error reporting. */ - def warning(pos: Position, msg: String, force: Boolean = false) { - if (reportErrors || force) reporter.warning(pos, msg) + def warning(pos: Position, msg: String) { + if (reportErrors) reporter.warning(pos, msg) else if (bufferErrors) reportBuffer += (pos -> msg) } diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index 7440f69e93..fbea69db5a 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -572,11 +572,11 @@ trait TypeDiagnostics { } else f } def apply(tree: Tree): Tree = { - // Error suppression will squash some of these warnings unless we circumvent it. + // Error suppression (in context.warning) would squash some of these warnings. // It is presumed if you are using a -Y option you would really like to hear - // the warnings you've requested. + // the warnings you've requested; thus, use reporter.warning. if (settings.warnDeadCode && context.unit.exists && treeOK(tree) && exprOK) - context.warning(tree.pos, "dead code following this construct", force = true) + reporter.warning(tree.pos, "dead code following this construct") tree } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index e0af229d3a..ce031e9cd7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2990,7 +2990,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper ConstructorsOrderError(stat) } - if (treeInfo.isPureExprForWarningPurposes(result)) context.warning(stat.pos, + if (!isPastTyper && treeInfo.isPureExprForWarningPurposes(result)) context.warning(stat.pos, "a pure expression does nothing in statement position; " + "you may be omitting necessary parentheses" ) -- cgit v1.2.3