Skip to content

Commit 135b7ca

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 55fcf06 commit 135b7ca

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
@@ -11,7 +11,7 @@ import Scopes.newScope
1111
import StdNames.nme
1212
import Symbols.{ClassSymbol, NoSymbol, Symbol, defn, isDeprecated, requiredClass, requiredModule}
1313
import Types.*
14-
import reporting.{CodeAction, UnusedSymbol}
14+
import reporting.{Action, CodeAction, Diagnostic, UnusedSymbol, WConf}
1515
import rewrites.Rewrites
1616

1717
import MegaPhase.MiniPhase
@@ -557,7 +557,20 @@ object CheckUnused:
557557
for (msg, pos, origin) <- warnings do
558558
if origin.isEmpty then report.warning(msg, pos)
559559
else report.warning(msg, pos, origin)
560-
msg.actions.headOption.foreach(Rewrites.applyAction)
560+
// avoid rewrite if warning will be suppressed (would be nice if reporter knew how to apply actions)
561+
msg.actions.headOption match
562+
case Some(action) if ctx.run != null =>
563+
val dia =
564+
if origin.isEmpty then Diagnostic.Warning(msg, pos.sourcePos)
565+
else Diagnostic.LintWarning(msg, pos.sourcePos, origin)
566+
ctx.run.nn.suppressions.nowarnAction(dia) match
567+
case Action.Warning =>
568+
WConf.parsed.action(dia) match
569+
case Action.Error | Action.Warning =>
570+
Rewrites.applyAction(action)
571+
case _ =>
572+
case _ =>
573+
case _ =>
561574

562575
type MessageInfo = (UnusedSymbol, SrcPos, String) // string is origin or empty
563576

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)