From e1bdfad9d1a47d54f038bce0928101bf43a57a9a Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Wed, 22 Jan 2025 07:46:29 -0800 Subject: [PATCH] Filter help renders box border --- .../tools/dotc/reporting/MessageRendering.scala | 13 +++++++------ tests/neg/nowarn.check | 6 +++--- tests/warn/deprecated-origin-verbose.check | 12 ++++++------ tests/warn/i22412.check | 10 ++++++++++ tests/warn/i22412.scala | 3 +++ 5 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 tests/warn/i22412.check create mode 100644 tests/warn/i22412.scala diff --git a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala index 7db5112b6674..45caf480f65e 100644 --- a/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala +++ b/compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala @@ -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")) diff --git a/tests/neg/nowarn.check b/tests/neg/nowarn.check index 636cabd44d07..ff01de1788bd 100644 --- a/tests/neg/nowarn.check +++ b/tests/neg/nowarn.check @@ -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 -------------------------------------------------------- diff --git a/tests/warn/deprecated-origin-verbose.check b/tests/warn/deprecated-origin-verbose.check index e67efaf8668d..db0ee26fd779 100644 --- a/tests/warn/deprecated-origin-verbose.check +++ b/tests/warn/deprecated-origin-verbose.check @@ -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 diff --git a/tests/warn/i22412.check b/tests/warn/i22412.check new file mode 100644 index 000000000000..adbe698db058 --- /dev/null +++ b/tests/warn/i22412.check @@ -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` diff --git a/tests/warn/i22412.scala b/tests/warn/i22412.scala new file mode 100644 index 000000000000..870a264c1df1 --- /dev/null +++ b/tests/warn/i22412.scala @@ -0,0 +1,3 @@ + +class C: + @annotation.nowarn("v") def f = try 1 // warn