diff --git a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala index bcd80977efd5..52d6f42679c4 100644 --- a/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/compiler/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -54,8 +54,8 @@ class ScalaSettings extends Settings.SettingGroup { val plugin: Setting[List[String]] = MultiStringSetting ("-Xplugin", "paths", "Load a plugin from each classpath.") val disable: Setting[List[String]] = MultiStringSetting ("-Xplugin-disable", "plugin", "Disable plugins by name.") val require: Setting[List[String]] = MultiStringSetting ("-Xplugin-require", "plugin", "Abort if a named plugin is not loaded.") - val showPlugins: Setting[Boolean] = BooleanSetting ("-Xplugin-list", "Print a synopsis of loaded plugins.") - val pluginsDir: Setting[String] = StringSetting ("-Xpluginsdir", "path", "Path to search for plugin archives.", Defaults.scalaPluginPath) + val showPlugins: Setting[Boolean] = BooleanSetting ("-Xplugin-list", "Print a synopsis of loaded plugins.") + val pluginsDir: Setting[String] = StringSetting ("-Xpluginsdir", "path", "Path to search for plugin archives.", Defaults.scalaPluginPath) val pluginOptions: Setting[List[String]] = MultiStringSetting ("-P", "plugin:opt", "Pass an option to a plugin, e.g. -P::") /** -X "Advanced" settings @@ -76,6 +76,8 @@ class ScalaSettings extends Settings.SettingGroup { val XreplLineWidth: Setting[Int] = IntSetting("-Xrepl-line-width", "Maximal number of columns per line for REPL output", 390) val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.") val XverifySignatures: Setting[Boolean] = BooleanSetting("-Xverify-signatures", "Verify generic signatures in generated bytecode.") + val XsuppressMessageIds: Setting[List[String]] = MultiStringSetting("-Xsuppress-message-ids", "ids", "Suppress warnings if errorId is in this setting") + val XsuppressWarningKinds: Setting[List[String]] = MultiStringSetting("-Xsuppress-warning-kinds", "kinds", "Suppress warnings if error kind is in this setting") /** -Y "Private" settings */ val YoverrideVars: Setting[Boolean] = BooleanSetting("-Yoverride-vars", "Allow vars to be overridden.") @@ -91,7 +93,7 @@ class ScalaSettings extends Settings.SettingGroup { val Ylog: Setting[List[String]] = PhasesSetting("-Ylog", "Log operations during") val YemitTastyInClass: Setting[Boolean] = BooleanSetting("-Yemit-tasty-in-class", "Generate tasty in the .class file and add an empty *.hasTasty file.") val YlogClasspath: Setting[Boolean] = BooleanSetting("-Ylog-classpath", "Output information about what classpath is being applied.") - val YdisableFlatCpCaching: Setting[Boolean] = BooleanSetting("-YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.") + val YdisableFlatCpCaching: Setting[Boolean] = BooleanSetting("-YdisableFlatCpCaching", "Do not cache flat classpath representation of classpath elements from jars across compiler instances.") 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") diff --git a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala index aa6aebe17146..e735168af0c3 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala @@ -36,30 +36,65 @@ object Reporter { trait Reporting { this: Context => +import dotty.tools.dotc.reporting.diagnostic.MessageContainer + + type Escalation = MessageContainer => Option[MessageContainer] + val suppression: Escalation = (mc: MessageContainer) => for { + nonSilent <- silentWarnings(mc) + allowedId <- suppressIds(nonSilent) + allowedKind <- suppressKinds(allowedId) + escalated <- fatalWarnings(allowedKind) + } yield escalated + + def suppressedIds: List[Int] = this.settings.XsuppressMessageIds.value + .flatMap(id => scala.util.Try(id.toInt).toOption) + + def suppressIds(mc: MessageContainer) = { + val errornumber = mc.contained().errorId.errorNumber() + mc match { + case w: Error => Some(mc) + case m if suppressedIds.contains(m.contained().errorId.errorNumber()) => None + case _ => Some(mc) + } + } + + def supressedWarningKinds: List[String] = this.settings.XsuppressWarningKinds.value + def suppressKinds(mc: MessageContainer) = mc match { + case w: Warning if supressedWarningKinds.contains(w.contained().kind) => None + case _ => Some(mc) + } + + val silentWarnings: Escalation = (mc: MessageContainer) => mc match { + case _: Warning if this.settings.silentWarnings.value(this) => None + case _ => Some(mc) + } + + val fatalWarnings: Escalation = (mc: MessageContainer) => mc match { + case w: Warning if this.settings.XfatalWarnings.value(this) => Some(w.toError) + case _ => Some(mc) + } + + + def report(cont: MessageContainer) = suppression(cont) foreach reporter.report _ + /** For sending messages that are printed only if -verbose is set */ def inform(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = if (this.settings.verbose.value) this.echo(msg, pos) def echo(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new Info(msg, pos)) - - def reportWarning(warning: Warning): Unit = - if (!this.settings.silentWarnings.value) { - if (this.settings.XfatalWarnings.value) reporter.report(warning.toError) - else reporter.report(warning) - } + report(new Info(msg, pos)) def deprecationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - if (this.settings.deprecation.value) reportWarning(new DeprecationWarning(msg, pos)) + report(new DeprecationWarning(msg, pos)) def migrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reportWarning(new MigrationWarning(msg, pos)) + report(new MigrationWarning(msg, pos)) def uncheckedWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reportWarning(new UncheckedWarning(msg, pos)) + report(new UncheckedWarning(msg, pos)) def featureWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reportWarning(new FeatureWarning(msg, pos)) + report(new FeatureWarning(msg, pos)) def featureWarning(feature: String, featureDescription: String, isScala2Feature: Boolean, featureUseSite: Symbol, required: Boolean, pos: SourcePosition): Unit = { @@ -81,24 +116,25 @@ trait Reporting { this: Context => val msg = s"$featureDescription $req be enabled\nby making the implicit value $fqname visible.$explain" if (required) error(msg, pos) - else reportWarning(new FeatureWarning(msg, pos)) + else report(new FeatureWarning(msg, pos)) } def warning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reportWarning(new Warning(msg, pos)) + report(new Warning(msg, pos)) + def strictWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = if (this.settings.strict.value) error(msg, pos) - else reportWarning(new ExtendMessage(() => msg)(_ + "\n(This would be an error under strict mode)").warning(pos)) + else report(new ExtendMessage(() => msg)(_ + "\n(This would be an error under strict mode)").warning(pos)) def error(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report(new Error(msg, pos)) + report(new Error(msg, pos)) def errorOrMigrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = if (ctx.scala2Mode) migrationWarning(msg, pos) else error(msg, pos) def restrictionError(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit = - reporter.report { + report { new ExtendMessage(() => msg)(m => s"Implementation restriction: $m").error(pos) } diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java index b4d74a835114..6388ad44c574 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java @@ -4,10 +4,9 @@ public enum ErrorMessageID { // IMPORTANT: Add new IDs only at the end and never remove IDs - LazyErrorId, // // errorNumber: -2 NoExplanationID, // errorNumber: -1 - + // Note: line number n contains error number n - 10 EmptyCatchOrFinallyBlockID, // errorNumber: 0 EmptyCatchBlockID, // errorNumber: 1 EmptyCatchAndFinallyBlockID, // errorNumber: 2