Skip to content

Commit

Permalink
Filter help renders box border
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Jan 22, 2025
1 parent 8c5b00d commit e1bdfad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
13 changes: 7 additions & 6 deletions compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,21 @@ trait MessageRendering {
sb.toString
}

private def appendFilterHelp(dia: Diagnostic, sb: StringBuilder): Unit =
private def appendFilterHelp(dia: Diagnostic, sb: StringBuilder)(using Context, Level, Offset): Unit =
extension (sb: StringBuilder) def nl: sb.type = sb.append(EOL).append(offsetBox)
import dia.msg
val hasId = msg.errorId.errorNumber >= 0
val (category, origin) = dia match
case _: UncheckedWarning => ("unchecked", "")
case _: UncheckedWarning => ("unchecked", "")
case w: DeprecationWarning => ("deprecation", w.origin)
case _: FeatureWarning => ("feature", "")
case _ => ("", "")
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:")
sb.nl.append("Matching filters for @nowarn or -Wconf:")
entitled = true
sb.append(EOL).append(" - ").append(what).append(value)
sb.nl.append(" - ").append(what).append(value)
if hasId then
addHelp("id=E")(msg.errorId.errorNumber.toString)
addHelp("name=")(msg.errorId.productPrefix.stripSuffix("ID"))
Expand Down
6 changes: 3 additions & 3 deletions tests/neg/nowarn.check
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
| ^^^^^
| A try without catch or finally is equivalent to putting
| its body in a block; no exceptions are handled.
Matching filters for @nowarn or -Wconf:
- id=E2
- name=EmptyCatchAndFinallyBlock
|Matching filters for @nowarn or -Wconf:
| - id=E2
| - name=EmptyCatchAndFinallyBlock
|
| longer explanation available when compiling with `-explain`
-- [E129] Potential Issue Warning: tests/neg/nowarn.scala:15:11 --------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions tests/warn/deprecated-origin-verbose.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
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
|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
|Matching filters for @nowarn or -Wconf:
| - cat=deprecation
| - origin=p.Crude
10 changes: 10 additions & 0 deletions tests/warn/i22412.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- [E002] Syntax Warning: tests/warn/i22412.scala:3:34 -----------------------------------------------------------------
3 | @annotation.nowarn("v") def f = try 1 // warn
| ^^^^^
| A try without catch or finally is equivalent to putting
| its body in a block; no exceptions are handled.
|Matching filters for @nowarn or -Wconf:
| - id=E2
| - name=EmptyCatchAndFinallyBlock
|
| longer explanation available when compiling with `-explain`
3 changes: 3 additions & 0 deletions tests/warn/i22412.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

class C:
@annotation.nowarn("v") def f = try 1 // warn

0 comments on commit e1bdfad

Please sign in to comment.