Skip to content

Commit dbd0b99

Browse files
som-snytttgodzik
authored andcommitted
Reporter applies lint actions
Instead of testing whether to emit actions by probing suppressions, just let the reporter apply LintWarning actions when the warning is actually reported.
1 parent 993f558 commit dbd0b99

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

compiler/src/dotty/tools/dotc/reporting/Diagnostic.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ object Diagnostic:
4242
*/
4343
trait OriginWarning(val origin: String):
4444
self: Warning =>
45+
object OriginWarning:
46+
val NoOrigin = "..."
4547

4648
/** Lints are likely to be filtered. Provide extra axes for filtering by `-Wconf`.
4749
*/
48-
class LintWarning(msg: Message, pos: SourcePosition, origin: String)
50+
class LintWarning(msg: Message, pos: SourcePosition, origin: String = OriginWarning.NoOrigin)
4951
extends Warning(msg, pos), OriginWarning(origin)
5052

5153
class Warning(

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import dotty.tools.dotc.core.Mode
99
import dotty.tools.dotc.core.Symbols.{NoSymbol, Symbol}
1010
import dotty.tools.dotc.reporting.Diagnostic.*
1111
import dotty.tools.dotc.reporting.Message.*
12+
import dotty.tools.dotc.rewrites.Rewrites
1213
import dotty.tools.dotc.util.NoSourcePosition
1314

1415
import java.io.{BufferedReader, PrintWriter}
@@ -174,6 +175,8 @@ abstract class Reporter extends interfaces.ReporterResult {
174175
handleRecursive("error reporting", dia.message, ex)
175176
dia match {
176177
case w: Warning =>
178+
if w.isInstanceOf[LintWarning] then
179+
w.msg.actions.foreach(Rewrites.applyAction)
177180
warnings = w :: warnings
178181
_warningCount += 1
179182
case e: Error =>

compiler/src/dotty/tools/dotc/reporting/WConf.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ enum MessageFilter:
3434
pattern.findFirstIn(path).nonEmpty
3535
case Origin(pattern) =>
3636
message match
37-
case message: OriginWarning => pattern.findFirstIn(message.origin).nonEmpty
37+
case message: OriginWarning if message.origin != OriginWarning.NoOrigin =>
38+
pattern.findFirstIn(message.origin).nonEmpty
3839
case _ => false
3940
case None => false
4041

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -527,29 +527,15 @@ object CheckUnused:
527527

528528
def reportUnused()(using Context): Unit = if !refInfos.isNullified then
529529
for (msg, pos, origin) <- warnings do
530-
if origin.isEmpty then report.warning(msg, pos)
531-
else report.warning(msg, pos, origin)
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 _ =>
530+
report.warning(msg, pos, origin)
546531

547532
type MessageInfo = (UnusedSymbol, SrcPos, String) // string is origin or empty
548533

549534
def warnings(using Context): Array[MessageInfo] =
550535
val actionable = ctx.settings.rewrite.value.nonEmpty
551536
val warnings = ArrayBuilder.make[MessageInfo]
552-
def warnAt(pos: SrcPos)(msg: UnusedSymbol, origin: String = ""): Unit = warnings.addOne((msg, pos, origin))
537+
def warnAt(pos: SrcPos)(msg: UnusedSymbol, origin: String = Diagnostic.OriginWarning.NoOrigin): Unit =
538+
warnings.addOne((msg, pos, origin))
553539
val infos = refInfos
554540

555541
// non-local sym was target of assignment or has a sibling setter that was referenced
@@ -712,7 +698,6 @@ object CheckUnused:
712698

713699
def checkImports() =
714700
import scala.jdk.CollectionConverters.given
715-
import Rewrites.ActionPatch
716701
type ImpSel = (Import, ImportSelector)
717702
def isUsed(sel: ImportSelector): Boolean = infos.sels.containsKey(sel)
718703
def warnImport(warnable: ImpSel, actions: List[CodeAction] = Nil): Unit =

0 commit comments

Comments
 (0)