Skip to content

Commit

Permalink
Merge pull request #14602 from griggt/fix-14576
Browse files Browse the repository at this point in the history
Fix #14576: Ensure unreported warning summaries are also emitted via sbt-bridge
  • Loading branch information
griggt authored Mar 3, 2022
2 parents 4274f48 + 993f08d commit 727395c
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 10 deletions.
12 changes: 10 additions & 2 deletions community-build/src/scala/dotty/communitybuild/projects.scala
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,8 @@ object projects:

lazy val shapeless = SbtCommunityProject(
project = "shapeless",
sbtTestCommand = "test",
sbtTestCommand = """set deriving/scalacOptions -= "-Xfatal-warnings"; set typeable/scalacOptions -= "-Xfatal-warnings"; test""",
// selectively disable -Xfatal-warnings due to deprecations
sbtDocCommand = forceDoc("typeable", "deriving", "data"),
scalacOptions = Nil // disable -Ysafe-init, due to -Xfatal-warnings
)
Expand Down Expand Up @@ -702,7 +703,14 @@ object projects:
lazy val akka = SbtCommunityProject(
project = "akka",
extraSbtArgs = List(s"-Dakka.build.scalaVersion=$testedCompilerVersion"),
sbtTestCommand = "set every targetSystemJdk := true; akka-actor-tests/Test/compile",
sbtTestCommand = List(
"set every targetSystemJdk := true",
// selectively disable -Xfatal-warnings due to deprecations
"""set actor/Compile/scalacOptions -= "-Xfatal-warnings"""",
"""set testkit/Compile/scalacOptions -= "-Xfatal-warnings"""",
"""set actorTests/Compile/scalacOptions -= "-Xfatal-warnings"""",
"akka-actor-tests/Test/compile",
).mkString("; "),
dependencies = () => List(scalatest, scalatestplusJunit, scalatestplusScalacheck)
)

Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,11 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
compileSources(sources)
}

/** Print summary; return # of errors encountered */
/** Print summary of warnings and errors encountered */
def printSummary(): Unit = {
printMaxConstraint()
val r = runContext.reporter
r.summarizeUnreportedWarnings
r.printSummary
}

Expand Down
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,15 @@ abstract class Reporter extends interfaces.ReporterResult {
b += countString(warningCount, "warning") + " found"
if (errorCount > 0)
b += countString(errorCount, "error") + " found"
for ((settingName, count) <- unreportedWarnings)
b += s"there were $count ${settingName.tail} warning(s); re-run with $settingName for details"
b.mkString("\n")
}

def summarizeUnreportedWarnings(using Context): Unit =
for (settingName, count) <- unreportedWarnings do
val were = if count == 1 then "was" else "were"
val msg = s"there $were ${countString(count, settingName.tail + " warning")}; re-run with $settingName for details"
report(Warning(msg, NoSourcePosition))

/** Print the summary of warnings and errors */
def printSummary(using Context): Unit = {
val s = summary
Expand Down
3 changes: 2 additions & 1 deletion compiler/test-resources/repl/reset-command
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
scala> def f(thread: Thread) = thread.stop()
there were 1 deprecation warning(s); re-run with -deprecation for details
there was 1 deprecation warning; re-run with -deprecation for details
1 warning found
def f(thread: Thread): Unit

scala>:reset -deprecation
Expand Down
3 changes: 2 additions & 1 deletion compiler/test-resources/repl/settings-command
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
scala> def f(thread: Thread) = thread.stop()
there were 1 deprecation warning(s); re-run with -deprecation for details
there was 1 deprecation warning; re-run with -deprecation for details
1 warning found
def f(thread: Thread): Unit

scala>:settings -deprecation foo.scala
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class CompilationTests {
compileFilesInDir("tests/pos-special/sourcepath/outer", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
compileFile("tests/pos-special/sourcepath/outer/nested/Test4.scala", defaultOptions.and("-sourcepath", "tests/pos-special/sourcepath")),
compileFilesInDir("tests/pos-special/fatal-warnings", defaultOptions.and("-Xfatal-warnings", "-deprecation", "-feature")),
compileFile("tests/pos-special/avoid-warn-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
compileFilesInDir("tests/pos-special/spec-t5545", defaultOptions),
compileFilesInDir("tests/pos-special/strawman-collections", allowDeepSubtypes),
compileFilesInDir("tests/pos-special/isInstanceOf", allowDeepSubtypes.and("-Xfatal-warnings")),
Expand Down Expand Up @@ -141,6 +140,7 @@ class CompilationTests {
compileFilesInDir("tests/neg-custom-args/no-experimental", defaultOptions.and("-Yno-experimental")),
compileDir("tests/neg-custom-args/impl-conv", defaultOptions.and("-Xfatal-warnings", "-feature")),
compileDir("tests/neg-custom-args/i13946", defaultOptions.and("-Xfatal-warnings", "-feature")),
compileFile("tests/neg-custom-args/avoid-warn-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
compileFile("tests/neg-custom-args/implicit-conversions.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
compileFile("tests/neg-custom-args/implicit-conversions-old.scala", defaultOptions.and("-Xfatal-warnings", "-feature")),
compileFile("tests/neg-custom-args/i3246.scala", scala2CompatMode),
Expand Down
17 changes: 17 additions & 0 deletions sbt-test/compilerReporter/i14576/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// lampepfl/dotty#14576, Writer is in a separate file and not declared `open`
// under -source:future this requires -language:adhocExtensions
class ExtWriter extends Writer

class Text(val str: String)

object Test:
// lampepfl/dotty#14500, requires implicitConversions feature
given Conversion[String, Text] = Text(_)
def f(x: Text) = println(x.str)
f("abc")

// private[this] and = _ are deprecated under -source:future
private[this] var x: AnyRef = _

// under -source:future, `_` is deprecated for wildcard arguments of types: use `?` instead
val xs: List[_] = Nil
1 change: 1 addition & 0 deletions sbt-test/compilerReporter/i14576/Writer.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Writer
38 changes: 38 additions & 0 deletions sbt-test/compilerReporter/i14576/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import sbt.internal.util.ConsoleAppender

scalaVersion := sys.props("plugin.scalaVersion")

lazy val assertFeatureSummary = taskKey[Unit]("checks that feature warning summary is emitted")
lazy val assertNoFeatureSummary = taskKey[Unit]("checks that no feature warning summary is emitted")
lazy val assertDeprecationSummary = taskKey[Unit]("checks that deprecation warning summary is emitted")
lazy val assertNoDeprecationSummary = taskKey[Unit]("checks that no deprecation warning summary is emitted")
lazy val resetMessages = taskKey[Unit]("empties the messages list")

lazy val root = (project in file("."))
.settings(
scalacOptions += "-source:future",
extraAppenders := { s => Seq(ConsoleAppender(FakePrintWriter)) },
assertFeatureSummary := {
assert {
FakePrintWriter.messages.exists(_.contains("there were 2 feature warnings; re-run with -feature for details"))
}
},
assertNoFeatureSummary := {
assert {
FakePrintWriter.messages.forall(!_.contains("; re-run with -feature for details"))
}
},
assertDeprecationSummary := {
assert {
FakePrintWriter.messages.exists(_.contains("there were 3 deprecation warnings; re-run with -deprecation for details"))
}
},
assertNoDeprecationSummary := {
assert {
FakePrintWriter.messages.forall(!_.contains("; re-run with -deprecation for details"))
}
},
resetMessages := {
FakePrintWriter.resetMessages
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object FakePrintWriter extends java.io.PrintWriter("fake-print-writer") {
@volatile var messages = List.empty[String]
def resetMessages = messages = List.empty[String]
override def println(x: String): Unit = messages = x :: messages
override def print(x: String): Unit = messages = x :: messages
}
19 changes: 19 additions & 0 deletions sbt-test/compilerReporter/i14576/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
> compile
> assertFeatureSummary
> assertDeprecationSummary

> resetMessages

> set scalacOptions += "-feature"
> compile
> assertNoFeatureSummary
> assertDeprecationSummary

> resetMessages

> set scalacOptions += "-deprecation"
> compile
> assertNoFeatureSummary
> assertNoDeprecationSummary

> resetMessages
2 changes: 2 additions & 0 deletions tests/init/pos/lazylist1.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import scala.language.implicitConversions

class LazyList[A]

object LazyList {
Expand Down
1 change: 1 addition & 0 deletions tests/neg-custom-args/avoid-warn-deprecation.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
there was 1 deprecation warning; re-run with -deprecation for details
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ object A {
object B {
A.foo
}
// nopos-error there was 1 deprecation warning; re-run with -deprecation for details
3 changes: 2 additions & 1 deletion tests/neg-custom-args/conditionalWarnings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ object Test {
val x: Int = "abc"
// OK, since -feature warnings are not enabled.
// The program compiles with final line
// there were 1 feature warning(s); re-run with -feature for details
// there was 1 feature warning; re-run with -feature for details
// nopos-error
}
1 change: 1 addition & 0 deletions tests/neg-custom-args/fatal-warnings/i12253.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
11 | case extractors.InlinedLambda(_, Select(_, name)) => Expr(name) // error // error
| ^
| the type test for q1.reflect.Select cannot be checked at runtime
there was 1 deprecation warning; re-run with -deprecation for details
2 changes: 1 addition & 1 deletion tests/neg-custom-args/fatal-warnings/i12253.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ object MacroUtils:

end Extractors
end MacroUtils

// nopos-error
1 change: 1 addition & 0 deletions tests/neg-custom-args/i13838.check
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
| Larger values might make a very large search problem succeed.
|
| longer explanation available when compiling with `-explain`
there was 1 feature warning; re-run with -feature for details

0 comments on commit 727395c

Please sign in to comment.