Skip to content

Commit

Permalink
More doc
Browse files Browse the repository at this point in the history
[Cherry-picked 3c873cf]
  • Loading branch information
som-snytt authored and WojciechMazur committed Dec 3, 2024
1 parent d0b20f2 commit 0684e71
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 18 deletions.
6 changes: 5 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private sealed trait WarningSettings:
"patterns",
default = List(),
descr =
s"""Configure compiler warnings.
raw"""Configure compiler warnings.
|Syntax: -Wconf:<filters>:<action>,<filters>:<action>,...
|multiple <filters> are combined with &, i.e., <filter>&...&<filter>
|
Expand All @@ -257,6 +257,9 @@ private sealed trait WarningSettings:
| - Source location: src=regex
| The regex is evaluated against the full source path.
|
| - Origin of warning: origin=regex
| The regex must match the full name (`package.Class.method`) of the deprecated entity.
|
|In verbose warning mode the compiler prints matching filters for warnings.
|Verbose mode can be enabled globally using `-Wconf:any:verbose`, or locally
|using the @nowarn annotation (example: `@nowarn("v") def test = try 1`).
Expand All @@ -276,6 +279,7 @@ private sealed trait WarningSettings:
|Examples:
| - change every warning into an error: -Wconf:any:error
| - silence deprecations: -Wconf:cat=deprecation:s
| - silence a deprecation: -Wconf:origin=java\.lang\.Thread\.getId:s
| - silence warnings in src_managed directory: -Wconf:src=src_managed/.*:s
|
|Note: on the command-line you might need to quote configurations containing `*` or `&`
Expand Down
39 changes: 22 additions & 17 deletions compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import util.{ SourcePosition, NoSourcePosition }
import util.Chars.{ LF, CR, FF, SU }
import scala.annotation.switch

import scala.collection.mutable
import scala.collection.mutable.StringBuilder

trait MessageRendering {
import Highlight.*
Expand Down Expand Up @@ -209,22 +209,27 @@ trait MessageRendering {
sb.toString
}

private def appendFilterHelp(dia: Diagnostic, sb: mutable.StringBuilder): Unit =
import dia.*
private def appendFilterHelp(dia: Diagnostic, sb: StringBuilder): Unit =
import dia.msg
val hasId = msg.errorId.errorNumber >= 0
val category = dia match {
case _: UncheckedWarning => "unchecked"
case _: DeprecationWarning => "deprecation"
case _: FeatureWarning => "feature"
case _ => ""
}
if (hasId || category.nonEmpty)
sb.append(EOL).append("Matching filters for @nowarn or -Wconf:")
if (hasId)
sb.append(EOL).append(" - id=E").append(msg.errorId.errorNumber)
sb.append(EOL).append(" - name=").append(msg.errorId.productPrefix.stripSuffix("ID"))
if (category.nonEmpty)
sb.append(EOL).append(" - cat=").append(category)
val (category, origin) = dia match
case _: UncheckedWarning => ("unchecked", "")
case w: DeprecationWarning => ("deprecation", w.origin)
case _: FeatureWarning => ("feature", "")
case _ => ("", "")
var entitled = false
def addHelp(what: String)(value: String): Unit =
if !entitled then
sb.append(EOL).append("Matching filters for @nowarn or -Wconf:")
entitled = true
sb.append(EOL).append(" - ").append(what).append(value)
if hasId then
addHelp("id=E")(msg.errorId.errorNumber.toString)
addHelp("name=")(msg.errorId.productPrefix.stripSuffix("ID"))
if category.nonEmpty then
addHelp("cat=")(category)
if origin.nonEmpty then
addHelp("origin=")(origin)

/** The whole message rendered from `msg` */
def messageAndPos(dia: Diagnostic)(using Context): String = {
Expand All @@ -236,7 +241,7 @@ trait MessageRendering {
else 0
given Level = Level(level)
given Offset = Offset(maxLineNumber.toString.length + 2)
val sb = mutable.StringBuilder()
val sb = StringBuilder()
val posString = posStr(pos, msg, diagnosticLevel(dia))
if (posString.nonEmpty) sb.append(posString).append(EOL)
if (pos.exists) {
Expand Down
14 changes: 14 additions & 0 deletions tests/warn/deprecated-origin-verbose.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Deprecation Warning: tests/warn/deprecated-origin-verbose.scala:12:18 -----------------------------------------------
12 | class D extends C // warn
| ^
| class C in package p is deprecated since 1.0: Old style
Matching filters for @nowarn or -Wconf:
- cat=deprecation
- origin=p.C
-- Deprecation Warning: tests/warn/deprecated-origin-verbose.scala:13:20 -----------------------------------------------
13 | class Oil extends Crude // warn
| ^^^^^
| class Crude in package p is deprecated since 1.0: Bad style
Matching filters for @nowarn or -Wconf:
- cat=deprecation
- origin=p.Crude
15 changes: 15 additions & 0 deletions tests/warn/deprecated-origin-verbose.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//> using options -deprecation -Wconf:any:verbose

package p:
@deprecated("Old style", since="1.0")
class C
@deprecated("Bad style", since="1.0")
class Crude

package q:
import annotation.*
import p.*
class D extends C // warn
class Oil extends Crude // warn
@nowarn("""origin=p\.Crude""")
class Language extends Crude // nowarn obvs

0 comments on commit 0684e71

Please sign in to comment.