Skip to content

Commit

Permalink
-nowarn is -Wconf:any:s
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed May 9, 2024
1 parent c37582b commit ce202a3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/compiler/scala/tools/nsc/Reporting.scala
Expand Up @@ -66,9 +66,12 @@ trait Reporting extends internal.Reporting { self: ast.Positions with Compilatio
conf.copy(filters = user ::: fixed)
}
else conf
val Migration = MessageFilter.Category(WarningCategory.Scala3Migration)
val boost = (settings.isScala3: @nowarn) && !conf.filters.exists(_._1.exists(_ == Migration))
if (boost) adjusted.copy(filters = adjusted.filters :+ (Migration :: Nil, Action.Error)) else adjusted
def Migration = MessageFilter.Category(WarningCategory.Scala3Migration)
if (settings.nowarn.value)
adjusted.copy(filters = adjusted.filters :+ (MessageFilter.Any :: Nil, Action.Silent))
else if ((settings.isScala3: @nowarn) && !conf.filters.exists(_._1.exists(_ == Migration)))
adjusted.copy(filters = adjusted.filters :+ (Migration :: Nil, Action.Error))
else adjusted
}

private lazy val quickfixFilters = {
Expand Down Expand Up @@ -397,7 +400,7 @@ trait Reporting extends internal.Reporting { self: ast.Positions with Compilatio
var seenMacroExpansionsFallingBack = false

// i.e., summarize warnings
def summarizeErrors(): Unit = if (!reporter.hasErrors && !settings.nowarn.value) {
def summarizeErrors(): Unit = if (!reporter.hasErrors) {
for (c <- summarizedWarnings.keys.toList.sortBy(_.name))
summarize(Action.WarningSummary, c)
for (c <- summarizedInfos.keys.toList.sortBy(_.name))
Expand Down
Expand Up @@ -26,7 +26,7 @@ class ConsoleReporter(val settings: Settings, val reader: BufferedReader, val wr

override def finish(): Unit = {
import reflect.internal.util.StringOps.countElementsAsString
if (!settings.nowarn.value && hasWarnings)
if (hasWarnings)
writer.println(countElementsAsString(warningCount, WARNING.toString.toLowerCase))
if (hasErrors)
writer.println(countElementsAsString(errorCount, ERROR.toString.toLowerCase))
Expand Down
Expand Up @@ -45,7 +45,7 @@ trait StandardScalaSettings { _: MutableSettings =>
}
val g = ChoiceSetting ("-g", "level", "Set level of generated debugging info.", List("none", "source", "line", "vars", "notailcalls"), "vars")
val help = BooleanSetting ("-help", "Print a synopsis of standard options") withAbbreviation "--help" withAbbreviation("-h")
val nowarn = BooleanSetting ("-nowarn", "Generate no warnings.") withAbbreviation "--no-warnings" withPostSetHook { s => if (s.value) maxwarns.value = 0 }
val nowarn = BooleanSetting ("-nowarn", "Silence warnings. (-Wconf:any:s)") withAbbreviation "--no-warnings"
val optimise: BooleanSetting // depends on post hook which mutates other settings
val print = BooleanSetting ("-print", "Print program with Scala-specific features removed.") withAbbreviation "--print"
val quickfix = MultiStringSetting(
Expand Down
4 changes: 4 additions & 0 deletions test/files/neg/t12664.check
@@ -0,0 +1,4 @@
warning: 1 lint warning; change -Wconf for cat=lint to display individual messages
error: No warnings can be incurred under -Werror.
1 warning
1 error
14 changes: 14 additions & 0 deletions test/files/neg/t12664.scala
@@ -0,0 +1,14 @@
//> using options -nowarn -Wconf:cat=lint-missing-interpolator:ws -Werror -Xlint -Xsource:3
//> xusing options -Wconf:cat=lint-missing-interpolator:ws -Werror -Xlint -Xsource:3

trait T {
def g[A]: Option[A]
}

class C extends T {
def f: Unit = 42 // suppressed other warning for expr, lint for parens

override def g[A] = None // suppressed migration warning, not boosted to error under --no-warnings

def oops = "$f" // summarized lint
}

0 comments on commit ce202a3

Please sign in to comment.