Skip to content

Commit 6ee08b8

Browse files
committed
Unused lint does not rewrite suppressed warnings
Partially duplicates reporter logic; reporter could auto-apply actions, maybe keying off diagnostic ID.
1 parent 9f70200 commit 6ee08b8

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import dotty.tools.dotc.core.StdNames.nme
1515
import dotty.tools.dotc.core.Symbols.{ClassSymbol, NoSymbol, Symbol, defn, isDeprecated, requiredClass, requiredModule}
1616
import dotty.tools.dotc.core.Types.*
1717
import dotty.tools.dotc.report
18-
import dotty.tools.dotc.reporting.{CodeAction, UnusedSymbol}
18+
import dotty.tools.dotc.reporting.{Action, CodeAction, Diagnostic, UnusedSymbol, WConf}
1919
import dotty.tools.dotc.rewrites.Rewrites
2020
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
2121
import dotty.tools.dotc.typer.{ImportInfo, Typer}
@@ -559,7 +559,20 @@ object CheckUnused:
559559
for (msg, pos, origin) <- warnings do
560560
if origin.isEmpty then report.warning(msg, pos)
561561
else report.warning(msg, pos, origin)
562-
msg.actions.headOption.foreach(Rewrites.applyAction)
562+
// avoid rewrite if warning will be suppressed (would be nice if reporter knew how to apply actions)
563+
msg.actions.headOption match
564+
case Some(action) if ctx.run != null =>
565+
val dia =
566+
if origin.isEmpty then Diagnostic.Warning(msg, pos.sourcePos)
567+
else Diagnostic.LintWarning(msg, pos.sourcePos, origin)
568+
ctx.run.nn.suppressions.nowarnAction(dia) match
569+
case Action.Warning =>
570+
WConf.parsed.action(dia) match
571+
case Action.Error | Action.Warning =>
572+
Rewrites.applyAction(action)
573+
case _ =>
574+
case _ =>
575+
case _ =>
563576

564577
type MessageInfo = (UnusedSymbol, SrcPos, String) // string is origin or empty
565578

tests/rewrites/i24009.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -Wunused:imports -rewrite -Wconf:name=UnusedSymbol&origin=p.C:s
2+
3+
package p:
4+
class C
5+
6+
package q:
7+
import p.C // nowarn and no rewrite
8+
9+
class D

0 commit comments

Comments
 (0)