Skip to content

Commit f80b80d

Browse files
som-snytttgodzik
authored andcommitted
Introduce -Yreporter
1 parent 40d3b08 commit f80b80d

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,26 @@ class Driver {
7979
MacroClassLoader.init(ictx)
8080
Positioned.init(using ictx)
8181

82-
inContext(ictx) {
82+
inContext(ictx):
8383
if !ctx.settings.YdropComments.value || ctx.settings.YreadComments.value then
8484
ictx.setProperty(ContextDoc, new ContextDocstrings)
8585
val fileNamesOrNone = command.checkUsage(summary, sourcesRequired)(using ctx.settings)(using ctx.settingsState)
8686
fileNamesOrNone.map: fileNames =>
8787
val files = fileNames.map(ctx.getFile)
8888
(files, fromTastySetup(files))
8989
.tap: _ =>
90-
if ctx.settings.YnoReporter.value then
91-
ictx.setReporter(Reporter.SilentReporter())
92-
}
90+
if !ctx.settings.Yreporter.isDefault then
91+
ctx.settings.Yreporter.value match
92+
case "help" =>
93+
case reporterClassName =>
94+
try
95+
Class.forName(reporterClassName).getDeclaredConstructor().newInstance() match
96+
case userReporter: Reporter =>
97+
ictx.setReporter(userReporter)
98+
case badReporter => report.error:
99+
em"Not a reporter: ${ctx.settings.Yreporter.value}"
100+
catch case e: ReflectiveOperationException => report.error:
101+
em"Could not create reporter ${ctx.settings.Yreporter.value}: ${e}"
93102
}
94103

95104
/** Setup extra classpath of tasty and jar files */

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ private sealed trait YSettings:
377377
val YdisableFlatCpCaching: Setting[Boolean] = BooleanSetting("-YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.")
378378

379379
val Yscala2Unpickler: Setting[String] = StringSetting("-Yscala2-unpickler", "", "Control where we may get Scala 2 symbols from. This is either \"always\", \"never\", or a classpath.", "always")
380-
val YnoReporter: Setting[Boolean] = BooleanSetting("Yno-reporter", "Diagnostics are silently consumed")
380+
val YnoReporter: Setting[Boolean] = BooleanSetting("-Yno-reporter", "Diagnostics are silently consumed")
381+
val Yreporter: Setting[String] = StringSetting(name = "-Yreporter", helpArg = "<class>", descr = "Specify a dotty.tools.dotc.reporting.Reporter", default = "dotty.tools.dotc.reporting.ConsoleReporter")
381382

382383
val YnoImports: Setting[Boolean] = BooleanSetting("-Yno-imports", "Compile without importing scala.*, java.lang.*, or Predef.")
383384
val Yimports: Setting[List[String]] = MultiStringSetting("-Yimports", helpArg="", "Custom root imports. If set, none of scala.*, java.lang.*, or Predef.* will be imported unless explicitly included.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object Reporter {
3030
override def report(dia: Diagnostic)(using Context): Unit = ()
3131
}
3232

33-
/** A reporter for -Yno-reporter [sic] */
33+
/** A silent reporter for testing */
3434
class SilentReporter extends Reporter:
3535
def doReport(dia: Diagnostic)(using Context): Unit = ()
3636

compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class SemanticdbTests:
144144
"-Xignore-scala2-macros",
145145
"-usejavacp",
146146
"-Wunused:all",
147-
"-Yno-reporter",
147+
"-Yreporter:dotty.tools.dotc.reporting.Reporter$SilentReporter",
148148
) ++ inputFiles().map(_.toString)
149149
val exit = Main.process(args)
150150
assertFalse(s"dotc errors: ${exit.errorCount}", exit.hasErrors)

0 commit comments

Comments
 (0)