Skip to content

Commit 0d99c7a

Browse files
committed
Note if a nowarn was superseded
1 parent 587bbf4 commit 0d99c7a

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,21 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
9292
mySuspendedMessages.getOrElseUpdate(warning.pos.source, mutable.LinkedHashSet.empty) += warning
9393

9494
def nowarnAction(dia: Diagnostic): Action.Warning.type | Action.Verbose.type | Action.Silent.type =
95-
mySuppressions.getOrElse(dia.pos.source, Nil).find(_.matches(dia)) match {
96-
case Some(s) =>
95+
mySuppressions.get(dia.pos.source) match
96+
case Some(suppressions) =>
97+
val matching = suppressions.iterator.filter(_.matches(dia))
98+
if matching.hasNext then
99+
val s = matching.next()
100+
for other <- matching do
101+
if !other.used then
102+
other.markSuperseded() // superseded unless marked used later
97103
s.markUsed()
98-
if (s.verbose) Action.Verbose
104+
if s.verbose then Action.Verbose
99105
else Action.Silent
100-
case _ =>
106+
else
101107
Action.Warning
102-
}
108+
case none =>
109+
Action.Warning
103110

104111
def registerNowarn(annotPos: SourcePosition, range: Span)(conf: String, pos: SrcPos)(using Context): Unit =
105112
var verbose = false
@@ -132,7 +139,8 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
132139
mySuspendedMessages.remove(source).foreach(_.foreach(ctx.reporter.issueIfNotSuppressed))
133140
}
134141

135-
def runFinished(hasErrors: Boolean): Unit =
142+
def runFinished()(using Context): Unit =
143+
val hasErrors = ctx.reporter.hasErrors
136144
// report suspended messages (in case the run finished before typer)
137145
mySuspendedMessages.keysIterator.toList.foreach(reportSuspendedMessages)
138146
// report unused nowarns only if all all phases are done
@@ -147,7 +155,9 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
147155
&& !suppressions.exists(s => s.ne(sup) && s.used && s.annotPos == sup.annotPos) // duplicate
148156
&& sup.filters != List(MessageFilter.None) // invalid suppression, don't report as unused
149157
then
150-
report.warning("@nowarn annotation does not suppress any warnings", sup.annotPos)
158+
val more = if sup.superseded then " but matches a diagnostic" else ""
159+
report.warning("@nowarn annotation does not suppress any warnings"+more, sup.annotPos)
160+
end suppressions
151161

152162
/** The compilation units currently being compiled, this may return different
153163
* results over time.
@@ -413,7 +423,7 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
413423
ctx.reporter.finalizeReporting()
414424
if (!ctx.reporter.hasErrors)
415425
Rewrites.writeBack()
416-
suppressions.runFinished(hasErrors = ctx.reporter.hasErrors)
426+
suppressions.runFinished()
417427
while (finalizeActions.nonEmpty && canProgress()) {
418428
val action = finalizeActions.remove(0)
419429
action()

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,16 @@ object WConf:
138138
else Right(WConf(configs))
139139

140140
class Suppression(val annotPos: SourcePosition, val filters: List[MessageFilter], val start: Int, val end: Int, val verbose: Boolean):
141-
private var _used = false
142-
def used: Boolean = _used
141+
inline def unusedState = 0
142+
inline def usedState = 1
143+
inline def supersededState = 2
144+
private var _used = unusedState
145+
def used: Boolean = _used == usedState
146+
def superseded: Boolean = _used == supersededState
143147
def markUsed(): Unit =
144-
_used = true
148+
_used = usedState
149+
def markSuperseded(): Unit =
150+
_used = supersededState
145151
def matches(dia: Diagnostic): Boolean =
146152
val pos = dia.pos
147153
pos.exists && start <= pos.start && pos.end <= end && filters.forall(_.matches(dia))

tests/warn/i23651.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ class A
88
@deprecated
99
class B
1010

11+
@nowarn("msg=trait C is deprecated") // warn
12+
// @nowarn annotation does not suppress any warnings
1113
@nowarn("msg=class A is deprecated")
12-
@nowarn("cat=deprecation&msg=class A is deprecated") // warn @nowarn annotation does not suppress any warnings
14+
@nowarn("cat=deprecation&msg=class A is deprecated") // warn
15+
// @nowarn annotation does not suppress any warnings but matches a diagnostic
1316
@nowarn("cat=deprecation&msg=class B is deprecated")
14-
trait C1 {
17+
trait C1:
1518
def a: A
1619
def b: B
17-
}
1820

1921
@nowarn("cat=deprecation&msg=class B is deprecated")
20-
@nowarn("cat=deprecation&msg=class B is deprecated") // warn @nowarn annotation does not suppress any warnings
22+
@nowarn("cat=deprecation&msg=class B is deprecated") // warn
23+
// @nowarn annotation does not suppress any warnings but matches a diagnostic
2124
@nowarn("cat=deprecation&msg=class A is deprecated")
22-
trait C2 {
25+
trait C2:
2326
def a: A
2427
def b: B
25-
}

0 commit comments

Comments
 (0)