Skip to content

Commit a9be669

Browse files
committed
Option warnings are conditional
1 parent b1f00a7 commit a9be669

File tree

6 files changed

+25
-13
lines changed

6 files changed

+25
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ trait CliCommand:
123123
*/
124124
def checkUsage(summary: ArgsSummary, sourcesRequired: Boolean)(using settings: ConcreteSettings)(using SettingsState, Context): Option[List[String]] =
125125
// Print all warnings encountered during arguments parsing
126-
summary.warnings.foreach(report.warning(_))
126+
summary.warnings.foreach(report.configurationWarning(_))
127127

128128
if summary.errors.nonEmpty then
129129
summary.errors foreach (report.error(_))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ trait CommonScalaSettings:
108108
val javaOutputVersion: Setting[String] = ChoiceSetting("-java-output-version", "version", "Compile code with classes specific to the given version of the Java platform available on the classpath and emit bytecode for this version. Corresponds to -release flag in javac.", ScalaSettings.supportedReleaseVersions, "", aliases = List("-release", "--release"))
109109
val scalaOutputVersion: Setting[String] = ChoiceSetting("-scala-output-version", "version", "Emit TASTy files that can be consumed by specified version of the compiler. The compilation will fail if for any reason valid TASTy cannot be produced (e.g. the code contains references to some parts of the standard library API that are missing in the older stdlib or uses language features unexpressible in the older version of TASTy format)", ScalaSettings.supportedScalaReleaseVersions, "")
110110

111+
val configuration: Setting[Boolean] = BooleanSetting("-configuration", "Warn about conflicting and redundant tool options", aliases = List("--configuration"))
111112
val deprecation: Setting[Boolean] = BooleanSetting("-deprecation", "Emit warning and location for usages of deprecated APIs.", aliases = List("--deprecation"))
112113
val feature: Setting[Boolean] = BooleanSetting("-feature", "Emit warning and location for usages of features that should be imported explicitly.", aliases = List("--feature"))
113114
val explain: Setting[Boolean] = BooleanSetting("-explain", "Explain errors in more detail.", aliases = List("--explain"))

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ object report:
2323
private def issueWarning(warning: Warning)(using Context): Unit =
2424
ctx.reporter.report(warning)
2525

26+
def configurationWarning(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
27+
issueWarning(ConfigurationWarning(msg, pos.sourcePos))
28+
2629
def deprecationWarning(msg: Message, pos: SrcPos = NoSourcePosition)(using Context): Unit =
2730
issueWarning(new DeprecationWarning(msg, pos.sourcePos))
2831

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ object Diagnostic:
7777
def enablingOption(using Context): Setting[Boolean] = ctx.settings.deprecation
7878
}
7979

80+
class ConfigurationWarning(
81+
msg: Message,
82+
pos: SourcePosition
83+
) extends ConditionalWarning(msg, pos) {
84+
def enablingOption(using Context): Setting[Boolean] = ctx.settings.configuration
85+
}
86+
8087
class MigrationWarning(
8188
msg: Message,
8289
pos: SourcePosition

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,13 @@ abstract class Reporter extends interfaces.ReporterResult {
205205
incompleteHandler(dia, ctx)
206206

207207
/** Summary of warnings and errors */
208-
def summary: String = {
209-
val b = new mutable.ListBuffer[String]
208+
def summary: String =
209+
val b = mutable.ListBuffer.empty[String]
210210
if (warningCount > 0)
211211
b += countString(warningCount, "warning") + " found"
212212
if (errorCount > 0)
213213
b += countString(errorCount, "error") + " found"
214214
b.mkString("\n")
215-
}
216215

217216
def summarizeUnreportedWarnings(using Context): Unit =
218217
for (settingName, count) <- unreportedWarnings do
@@ -221,10 +220,10 @@ abstract class Reporter extends interfaces.ReporterResult {
221220
report(Warning(msg, NoSourcePosition))
222221

223222
/** Print the summary of warnings and errors */
224-
def printSummary(using Context): Unit = {
225-
val s = summary
226-
if (s != "") report(new Info(s, NoSourcePosition))
227-
}
223+
def printSummary(using Context): Unit =
224+
summary match
225+
case "" =>
226+
case s => report(Info(s, NoSourcePosition))
228227

229228
/** Returns a string meaning "n elements". */
230229
protected def countString(n: Int, elements: String): String = n match {

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import scala.util.matching.Regex
1414
enum MessageFilter:
1515
def matches(message: Diagnostic): Boolean = this match
1616
case Any => true
17+
case Configuration => message.isInstanceOf[Diagnostic.ConfigurationWarning]
1718
case Deprecated => message.isInstanceOf[Diagnostic.DeprecationWarning]
1819
case Feature => message.isInstanceOf[Diagnostic.FeatureWarning]
1920
case Unchecked => message.isInstanceOf[Diagnostic.UncheckedWarning]
@@ -23,7 +24,7 @@ enum MessageFilter:
2324
case MessageID(errorId) => message.msg.errorId == errorId
2425
case None => false
2526

26-
case Any, Deprecated, Feature, Unchecked, None
27+
case Any, Configuration, Deprecated, Feature, Unchecked, None
2728
case MessagePattern(pattern: Regex)
2829
case MessageID(errorId: ErrorMessageID)
2930

@@ -79,10 +80,11 @@ object WConf:
7980
catch case _: IllegalArgumentException => Left(s"unknown error message name: $conf")
8081

8182
case "cat" => conf match
82-
case "deprecation" => Right(Deprecated)
83-
case "feature" => Right(Feature)
84-
case "unchecked" => Right(Unchecked)
85-
case _ => Left(s"unknown category: $conf")
83+
case "configuration" => Right(Configuration)
84+
case "deprecation" => Right(Deprecated)
85+
case "feature" => Right(Feature)
86+
case "unchecked" => Right(Unchecked)
87+
case _ => Left(s"unknown category: $conf")
8688
case _ => Left(s"unknown filter: $filter")
8789
case _ => Left(s"unknown filter: $s")
8890

0 commit comments

Comments
 (0)