Skip to content

Commit 70d7f0c

Browse files
committed
Ensure unreported warning summaries are also emitted via sbt-bridge
The sbt-bridge uses a delegating reporter that overrides the base implementation of `printSummary` and delegates to the sbt implementation. However that implementation only provides summary reporting of warning and error counts, and the _compiler_ is responsible for emitting any summary diagnostics regarding unreported warnings. This commit separates emitting those unreported warning summaries from the base implementation of Reporter#printSummary so as not to be overriden by the DelegatingReporter in sbt-bridge.
1 parent fae7c09 commit 70d7f0c

File tree

7 files changed

+89
-3
lines changed

7 files changed

+89
-3
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,12 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
321321
compileSources(sources)
322322
}
323323

324-
/** Print summary; return # of errors encountered */
324+
/** Print summary of warnings and errors encountered */
325325
def printSummary(): Unit = {
326326
printMaxConstraint()
327327
val r = runContext.reporter
328328
r.printSummary
329+
r.summarizeUnreportedWarnings
329330
}
330331

331332
override def reset(): Unit = {

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,16 @@ abstract class Reporter extends interfaces.ReporterResult {
207207
b += countString(warningCount, "warning") + " found"
208208
if (errorCount > 0)
209209
b += countString(errorCount, "error") + " found"
210-
for ((settingName, count) <- unreportedWarnings)
211-
b += s"there were $count ${settingName.tail} warning(s); re-run with $settingName for details"
212210
b.mkString("\n")
213211
}
214212

213+
def summarizeUnreportedWarnings(using Context): Unit =
214+
val b = mutable.ListBuffer[String]()
215+
for (settingName, count) <- unreportedWarnings do
216+
b += s"there were $count ${settingName.tail} warning(s); re-run with $settingName for details"
217+
val s = b.mkString("\n")
218+
if s.nonEmpty then report(Info(s, NoSourcePosition))
219+
215220
/** Print the summary of warnings and errors */
216221
def printSummary(using Context): Unit = {
217222
val s = summary
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// lampepfl/dotty#14576, Writer is in a separate file and not declared `open`
2+
// under -source:future this requires -language:adhocExtensions
3+
class ExtWriter extends Writer
4+
5+
class Text(val str: String)
6+
7+
object Test:
8+
// lampepfl/dotty#14500, requires implicitConversions feature
9+
given Conversion[String, Text] = Text(_)
10+
def f(x: Text) = println(x.str)
11+
f("abc")
12+
13+
// private[this] and = _ are deprecated under -source:future
14+
private[this] var x: AnyRef = _
15+
16+
// under -source:future, `_` is deprecated for wildcard arguments of types: use `?` instead
17+
val xs: List[_] = Nil
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Writer
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import sbt.internal.util.ConsoleAppender
2+
3+
scalaVersion := sys.props("plugin.scalaVersion")
4+
5+
lazy val assertFeatureSummary = taskKey[Unit]("checks that feature warning summary is emitted")
6+
lazy val assertNoFeatureSummary = taskKey[Unit]("checks that no feature warning summary is emitted")
7+
lazy val assertDeprecationSummary = taskKey[Unit]("checks that deprecation warning summary is emitted")
8+
lazy val assertNoDeprecationSummary = taskKey[Unit]("checks that no deprecation warning summary is emitted")
9+
lazy val resetMessages = taskKey[Unit]("empties the messages list")
10+
11+
lazy val root = (project in file("."))
12+
.settings(
13+
scalacOptions += "-source:future",
14+
extraAppenders := { s => Seq(ConsoleAppender(FakePrintWriter)) },
15+
assertFeatureSummary := {
16+
assert {
17+
FakePrintWriter.messages.exists(_.contains("there were 2 feature warning(s); re-run with -feature for details"))
18+
}
19+
},
20+
assertNoFeatureSummary := {
21+
assert {
22+
FakePrintWriter.messages.forall(!_.contains("feature warning(s); re-run with -feature for details"))
23+
}
24+
},
25+
assertDeprecationSummary := {
26+
assert {
27+
FakePrintWriter.messages.exists(_.contains("there were 3 deprecation warning(s); re-run with -deprecation for details"))
28+
}
29+
},
30+
assertNoDeprecationSummary := {
31+
assert {
32+
FakePrintWriter.messages.forall(!_.contains("deprecation warning(s); re-run with -deprecation for details"))
33+
}
34+
},
35+
resetMessages := {
36+
FakePrintWriter.resetMessages
37+
},
38+
)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object FakePrintWriter extends java.io.PrintWriter("fake-print-writer") {
2+
@volatile var messages = List.empty[String]
3+
def resetMessages = messages = List.empty[String]
4+
override def println(x: String): Unit = messages = x :: messages
5+
override def print(x: String): Unit = messages = x :: messages
6+
}

sbt-test/compilerReporter/i14576/test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
> compile
2+
> assertFeatureSummary
3+
> assertDeprecationSummary
4+
5+
> resetMessages
6+
7+
> set scalacOptions += "-feature"
8+
> compile
9+
> assertNoFeatureSummary
10+
11+
> resetMessages
12+
13+
> set scalacOptions += "-deprecation"
14+
> compile
15+
> assertNoFeatureSummary
16+
> assertNoDeprecationSummary
17+
18+
> resetMessages

0 commit comments

Comments
 (0)