diff --git a/community-build/src/scala/dotty/communitybuild/projects.scala b/community-build/src/scala/dotty/communitybuild/projects.scala index 9168da954952..2497c10a525b 100644 --- a/community-build/src/scala/dotty/communitybuild/projects.scala +++ b/community-build/src/scala/dotty/communitybuild/projects.scala @@ -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 ) @@ -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) ) diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index 3c48e737cff8..daf7415b4af6 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -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 } diff --git a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala index 39ece915ca83..d5229efd58c5 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala @@ -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 diff --git a/compiler/test-resources/repl/reset-command b/compiler/test-resources/repl/reset-command index 5ec643f28b0e..0adf0d93a0d8 100644 --- a/compiler/test-resources/repl/reset-command +++ b/compiler/test-resources/repl/reset-command @@ -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 diff --git a/compiler/test-resources/repl/settings-command b/compiler/test-resources/repl/settings-command index db4b1af7343f..5e9912384435 100644 --- a/compiler/test-resources/repl/settings-command +++ b/compiler/test-resources/repl/settings-command @@ -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 diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 4ea8db553f54..8e199dd45420 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -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")), @@ -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), diff --git a/sbt-test/compilerReporter/i14576/Test.scala b/sbt-test/compilerReporter/i14576/Test.scala new file mode 100644 index 000000000000..d94a49145f81 --- /dev/null +++ b/sbt-test/compilerReporter/i14576/Test.scala @@ -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 diff --git a/sbt-test/compilerReporter/i14576/Writer.scala b/sbt-test/compilerReporter/i14576/Writer.scala new file mode 100644 index 000000000000..2d9d5f834994 --- /dev/null +++ b/sbt-test/compilerReporter/i14576/Writer.scala @@ -0,0 +1 @@ +class Writer diff --git a/sbt-test/compilerReporter/i14576/build.sbt b/sbt-test/compilerReporter/i14576/build.sbt new file mode 100644 index 000000000000..9831c23c103e --- /dev/null +++ b/sbt-test/compilerReporter/i14576/build.sbt @@ -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 + }, + ) diff --git a/sbt-test/compilerReporter/i14576/project/FakePrintWriter.scala b/sbt-test/compilerReporter/i14576/project/FakePrintWriter.scala new file mode 100644 index 000000000000..14d3bcdba5b4 --- /dev/null +++ b/sbt-test/compilerReporter/i14576/project/FakePrintWriter.scala @@ -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 +} diff --git a/sbt-test/compilerReporter/i14576/test b/sbt-test/compilerReporter/i14576/test new file mode 100644 index 000000000000..32bd16066861 --- /dev/null +++ b/sbt-test/compilerReporter/i14576/test @@ -0,0 +1,19 @@ +> compile +> assertFeatureSummary +> assertDeprecationSummary + +> resetMessages + +> set scalacOptions += "-feature" +> compile +> assertNoFeatureSummary +> assertDeprecationSummary + +> resetMessages + +> set scalacOptions += "-deprecation" +> compile +> assertNoFeatureSummary +> assertNoDeprecationSummary + +> resetMessages diff --git a/tests/init/pos/lazylist1.scala b/tests/init/pos/lazylist1.scala index 3ff0f9bc449d..62a45ca28f00 100644 --- a/tests/init/pos/lazylist1.scala +++ b/tests/init/pos/lazylist1.scala @@ -1,3 +1,5 @@ +import scala.language.implicitConversions + class LazyList[A] object LazyList { diff --git a/tests/neg-custom-args/avoid-warn-deprecation.check b/tests/neg-custom-args/avoid-warn-deprecation.check new file mode 100644 index 000000000000..8fceac02ba8f --- /dev/null +++ b/tests/neg-custom-args/avoid-warn-deprecation.check @@ -0,0 +1 @@ +there was 1 deprecation warning; re-run with -deprecation for details diff --git a/tests/pos-special/avoid-warn-deprecation.scala b/tests/neg-custom-args/avoid-warn-deprecation.scala similarity index 55% rename from tests/pos-special/avoid-warn-deprecation.scala rename to tests/neg-custom-args/avoid-warn-deprecation.scala index 2b24b1094c87..fc8d71dd7f60 100644 --- a/tests/pos-special/avoid-warn-deprecation.scala +++ b/tests/neg-custom-args/avoid-warn-deprecation.scala @@ -6,3 +6,4 @@ object A { object B { A.foo } +// nopos-error there was 1 deprecation warning; re-run with -deprecation for details diff --git a/tests/neg-custom-args/conditionalWarnings.scala b/tests/neg-custom-args/conditionalWarnings.scala index b529cf6c6f81..a85e3c8af427 100644 --- a/tests/neg-custom-args/conditionalWarnings.scala +++ b/tests/neg-custom-args/conditionalWarnings.scala @@ -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 } diff --git a/tests/neg-custom-args/fatal-warnings/i12253.check b/tests/neg-custom-args/fatal-warnings/i12253.check index 1cda504511af..9a88c111f734 100644 --- a/tests/neg-custom-args/fatal-warnings/i12253.check +++ b/tests/neg-custom-args/fatal-warnings/i12253.check @@ -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 diff --git a/tests/neg-custom-args/fatal-warnings/i12253.scala b/tests/neg-custom-args/fatal-warnings/i12253.scala index 5fdf1c83504d..88cae0c9f3ec 100644 --- a/tests/neg-custom-args/fatal-warnings/i12253.scala +++ b/tests/neg-custom-args/fatal-warnings/i12253.scala @@ -25,4 +25,4 @@ object MacroUtils: end Extractors end MacroUtils - +// nopos-error diff --git a/tests/neg-custom-args/i13838.check b/tests/neg-custom-args/i13838.check index f6866dc6bf2a..365f25a4591f 100644 --- a/tests/neg-custom-args/i13838.check +++ b/tests/neg-custom-args/i13838.check @@ -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