Skip to content

Commit 7584a30

Browse files
committed
Option warnings are conditional
1 parent 5ce25fe commit 7584a30

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

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

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

155155
if summary.errors.nonEmpty then
156156
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
@@ -98,6 +98,7 @@ trait CommonScalaSettings:
9898
val silentWarnings: Setting[Boolean] = BooleanSetting("-nowarn", "Silence all warnings.", aliases = List("--no-warnings"))
9999

100100
val release: Setting[String] = ChoiceSetting("-release", "release", "Compile code with classes specific to the given version of the Java platform available on the classpath and emit bytecode for this version.", ScalaSettings.supportedReleaseVersions, "", aliases = List("--release"))
101+
val configuration: Setting[Boolean] = BooleanSetting("-configuration", "Warn about conflicting and redundant tool options", aliases = List("--configuration"))
101102
val deprecation: Setting[Boolean] = BooleanSetting("-deprecation", "Emit warning and location for usages of deprecated APIs.", aliases = List("--deprecation"))
102103
val feature: Setting[Boolean] = BooleanSetting("-feature", "Emit warning and location for usages of features that should be imported explicitly.", aliases = List("--feature"))
103104
val explain: Setting[Boolean] = BooleanSetting("-explain", "Explain errors in more detail.", aliases = List("--explain"))

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

Lines changed: 4 additions & 1 deletion
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

@@ -112,4 +115,4 @@ object report:
112115
case Nil => pos
113116
recur(pos.sourcePos, tpd.enclosingInlineds)
114117

115-
end report
118+
end report

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

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

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

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,22 +199,21 @@ abstract class Reporter extends interfaces.ReporterResult {
199199
incompleteHandler(dia, ctx)
200200

201201
/** Summary of warnings and errors */
202-
def summary: String = {
203-
val b = new mutable.ListBuffer[String]
202+
def summary: String =
203+
val b = mutable.ListBuffer.empty[String]
204204
if (warningCount > 0)
205205
b += countString(warningCount, "warning") + " found"
206206
if (errorCount > 0)
207207
b += countString(errorCount, "error") + " found"
208208
for ((settingName, count) <- unreportedWarnings)
209209
b += s"there were $count ${settingName.tail} warning(s); re-run with $settingName for details"
210210
b.mkString("\n")
211-
}
212211

213212
/** Print the summary of warnings and errors */
214-
def printSummary(using Context): Unit = {
215-
val s = summary
216-
if (s != "") report(new Info(s, NoSourcePosition))
217-
}
213+
def printSummary(using Context): Unit =
214+
summary match
215+
case "" =>
216+
case s => report(Info(s, NoSourcePosition))
218217

219218
/** Returns a string meaning "n elements". */
220219
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
@@ -13,6 +13,7 @@ import scala.util.matching.Regex
1313
enum MessageFilter:
1414
def matches(message: Diagnostic): Boolean = this match
1515
case Any => true
16+
case Configuration => message.isInstanceOf[Diagnostic.ConfigurationWarning]
1617
case Deprecated => message.isInstanceOf[Diagnostic.DeprecationWarning]
1718
case Feature => message.isInstanceOf[Diagnostic.FeatureWarning]
1819
case Unchecked => message.isInstanceOf[Diagnostic.UncheckedWarning]
@@ -22,7 +23,7 @@ enum MessageFilter:
2223
case MessageID(errorId) => message.msg.errorId == errorId
2324
case None => false
2425

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

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

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

0 commit comments

Comments
 (0)