From 7f21475c56b143f54491fb88041899366a281ee7 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Mon, 1 Sep 2014 04:39:50 -0700 Subject: SI-8410 Don't warn fatally on disabled flag Since boolean settings can now be set false by user, summary warnings should not be issued when the flag is explicitly off (as opposed to unset, default). In particular, `-Xfatal-warnings` should not fail if there were no warnings otherwise. ``` $ ~/scala-2.11.2/bin/scalac -d /tmp -deprecation:false test/files/pos/t8410.scala $ ~/scala-2.11.2/bin/scalac -d /tmp -deprecation:false -Xfatal-warnings test/files/pos/t8410.scala warning: there were three deprecation warnings; re-run with -deprecation for details error: No warnings can be incurred under -Xfatal-warnings. one warning found one error found ``` After this commit: ``` $ skalac -d /tmp -Xfatal-warnings test/files/pos/t8410.scala warning: there were three deprecation warnings; re-run with -deprecation for details error: No warnings can be incurred under -Xfatal-warnings. one warning found one error found $ skalac -d /tmp -deprecation:false -Xfatal-warnings test/files/pos/t8410.scala ``` Similarly for other collecting flags: ``` $ skalac -d /tmp -optimise -Yinline-warnings -deprecation:false -Xfatal-warnings test/files/pos/t8410.scala test/files/pos/t8410.scala:14: warning: Could not inline required method dropWhile because access level required by callee not matched by caller. def k = List(0).dropWhile(_ < 1) // inlining warns doubly ^ test/files/pos/t8410.scala:14: warning: At the end of the day, could not inline @inline-marked method dropWhile def k = List(0).dropWhile(_ < 1) // inlining warns doubly ^ error: No warnings can be incurred under -Xfatal-warnings. two warnings found one error found $ skalac -d /tmp -optimise -Yinline-warnings:false -deprecation:false -Xfatal-warnings test/files/pos/t8410.scala ``` Footnote: handling of deprecated locals also changed in 2014: ``` $ ~/scala-2.11.0-M7/bin/scalac -d /tmp -deprecation -Xfatal-warnings test/files/pos/t8410.scala test/files/pos/t8410.scala:8: warning: method f in object Test is deprecated: Console println f // warns ^ error: No warnings can be incurred under -Xfatal-warnings. one warning found one error found $ ~/scala-2.11.0-M8/bin/scalac -d /tmp -deprecation -Xfatal-warnings test/files/pos/t8410.scala test/files/pos/t8410.scala:5: warning: method _f is deprecated: def g = { @deprecated("","") def _f = f ; _f } // warns in 2.11.0-M8 ^ test/files/pos/t8410.scala:6: warning: class X is deprecated: def x = { @deprecated("","") class X { def x = f } ; new X().x } // warns in 2.11.0-M8 ^ test/files/pos/t8410.scala:8: warning: method f in object Test is deprecated: Console println f // warns ^ error: No warnings can be incurred under -Xfatal-warnings. three warnings found one error found ``` --- src/compiler/scala/tools/nsc/Reporting.scala | 9 ++++++--- test/files/pos/t8410.flags | 1 + test/files/pos/t8410.scala | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 test/files/pos/t8410.flags create mode 100644 test/files/pos/t8410.scala diff --git a/src/compiler/scala/tools/nsc/Reporting.scala b/src/compiler/scala/tools/nsc/Reporting.scala index b164f395fe..6ae5ec3c1d 100644 --- a/src/compiler/scala/tools/nsc/Reporting.scala +++ b/src/compiler/scala/tools/nsc/Reporting.scala @@ -32,14 +32,17 @@ trait Reporting extends scala.reflect.internal.Reporting { self: ast.Positions w def warn(pos: Position, msg: String) = if (option) reporter.warning(pos, msg) else if (!(warnings contains pos)) warnings += ((pos, msg)) - def summarize() = - if (warnings.nonEmpty && (option.isDefault || settings.fatalWarnings)) { + def summarize() = { + def turnedOff = option.isSetByUser && !option + def moreInfos = option.isDefault || settings.fatalWarnings + if (warnings.nonEmpty && !turnedOff && moreInfos) { val numWarnings = warnings.size val warningVerb = if (numWarnings == 1) "was" else "were" val warningCount = countElementsAsString(numWarnings, s"$what warning") reporter.warning(NoPosition, s"there $warningVerb $warningCount; re-run with ${option.name} for details") } + } } // This change broke sbt; I gave it the thrilling name of uncheckedWarnings0 so @@ -105,4 +108,4 @@ trait Reporting extends scala.reflect.internal.Reporting { self: ast.Positions w reporter.error(NoPosition, "No warnings can be incurred under -Xfatal-warnings.") } } -} \ No newline at end of file +} diff --git a/test/files/pos/t8410.flags b/test/files/pos/t8410.flags new file mode 100644 index 0000000000..dcd5943c2f --- /dev/null +++ b/test/files/pos/t8410.flags @@ -0,0 +1 @@ +-optimise -Xfatal-warnings -deprecation:false -Yinline-warnings:false diff --git a/test/files/pos/t8410.scala b/test/files/pos/t8410.scala new file mode 100644 index 0000000000..4d862311fa --- /dev/null +++ b/test/files/pos/t8410.scala @@ -0,0 +1,15 @@ + +object Test extends App { + @deprecated("","") def f = 42 + @deprecated("","") def z = f + def g = { @deprecated("","") def _f = f ; _f } // warns in 2.11.0-M8 + def x = { @deprecated("","") class X { def x = f } ; new X().x } // warns in 2.11.0-M8 + Console println g + Console println f // warns + + @deprecated("","") trait T + object T extends T { def t = f } + Console println T.t + + def k = List(0).dropWhile(_ < 1) // inlining warns doubly +} -- cgit v1.2.3 From 6076d61aef732b89af9d2c803425f90fb0fc4686 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Mon, 1 Sep 2014 17:20:46 -0700 Subject: SI-8410 Summarize if warnings and not disabled Simplify the conditional and emit the summary if there were buffered warnings and the user didn't explicitly disable this setting. The working assumption is that using fatal-warnings to turn on summaries was either an outdated heuristic or just due to a faulty merge. Or wait, was it for -feature, which is not enabled when warnings are issued against it? --- src/compiler/scala/tools/nsc/Reporting.scala | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/compiler/scala/tools/nsc/Reporting.scala b/src/compiler/scala/tools/nsc/Reporting.scala index 6ae5ec3c1d..c9782de7c8 100644 --- a/src/compiler/scala/tools/nsc/Reporting.scala +++ b/src/compiler/scala/tools/nsc/Reporting.scala @@ -32,17 +32,14 @@ trait Reporting extends scala.reflect.internal.Reporting { self: ast.Positions w def warn(pos: Position, msg: String) = if (option) reporter.warning(pos, msg) else if (!(warnings contains pos)) warnings += ((pos, msg)) - def summarize() = { - def turnedOff = option.isSetByUser && !option - def moreInfos = option.isDefault || settings.fatalWarnings - if (warnings.nonEmpty && !turnedOff && moreInfos) { + def summarize() = + if (warnings.nonEmpty && (option.isDefault || option)) { val numWarnings = warnings.size val warningVerb = if (numWarnings == 1) "was" else "were" val warningCount = countElementsAsString(numWarnings, s"$what warning") reporter.warning(NoPosition, s"there $warningVerb $warningCount; re-run with ${option.name} for details") } - } } // This change broke sbt; I gave it the thrilling name of uncheckedWarnings0 so -- cgit v1.2.3