Skip to content

Commit 397d4d7

Browse files
som-snytttgodzik
authored andcommitted
Unused lint does not rewrite suppressed warnings
Partially duplicates reporter logic; reporter could auto-apply actions, maybe keying off diagnostic ID.
1 parent a04d02d commit 397d4d7

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import dotty.tools.dotc.core.StdNames.nme
1616
import dotty.tools.dotc.core.Symbols.{ClassSymbol, NoSymbol, Symbol, defn, isDeprecated, requiredClass, requiredModule}
1717
import dotty.tools.dotc.core.Types.*
1818
import dotty.tools.dotc.report
19-
import dotty.tools.dotc.reporting.{CodeAction, UnusedSymbol}
20-
import dotty.tools.dotc.rewrites.Rewrites
19+
import dotty.tools.dotc.reporting.{CodeAction, Diagnostic, UnusedSymbol}
20+
import dotty.tools.dotc.rewrites.Rewrites.ActionPatch
2121
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
2222
import dotty.tools.dotc.typer.{ImportInfo, Typer}
2323
import dotty.tools.dotc.typer.Deriving.OriginalTypeClass
@@ -529,7 +529,20 @@ object CheckUnused:
529529
for (msg, pos, origin) <- warnings do
530530
if origin.isEmpty then report.warning(msg, pos)
531531
else report.warning(msg, pos, origin)
532-
msg.actions.headOption.foreach(Rewrites.applyAction)
532+
// avoid rewrite if warning will be suppressed (would be nice if reporter knew how to apply actions)
533+
msg.actions.headOption match
534+
case Some(action) if ctx.run != null =>
535+
val dia =
536+
if origin.isEmpty then Diagnostic.Warning(msg, pos.sourcePos)
537+
else Diagnostic.LintWarning(msg, pos.sourcePos, origin)
538+
ctx.run.nn.suppressions.nowarnAction(dia) match
539+
case Action.Warning =>
540+
WConf.parsed.action(dia) match
541+
case Action.Error | Action.Warning =>
542+
Rewrites.applyAction(action)
543+
case _ =>
544+
case _ =>
545+
case _ =>
533546

534547
type MessageInfo = (UnusedSymbol, SrcPos, String) // string is origin or empty
535548

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)