@@ -92,14 +92,21 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
92
92
mySuspendedMessages.getOrElseUpdate(warning.pos.source, mutable.LinkedHashSet .empty) += warning
93
93
94
94
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
97
103
s.markUsed()
98
- if ( s.verbose) Action .Verbose
104
+ if s.verbose then Action .Verbose
99
105
else Action .Silent
100
- case _ =>
106
+ else
101
107
Action .Warning
102
- }
108
+ case none =>
109
+ Action .Warning
103
110
104
111
def registerNowarn (annotPos : SourcePosition , range : Span )(conf : String , pos : SrcPos )(using Context ): Unit =
105
112
var verbose = false
@@ -118,12 +125,10 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
118
125
.merge
119
126
addSuppression :
120
127
Suppression (annotPos, filters, range.start, range.end, verbose)
121
- .tap: sup =>
122
- if filters == List (MessageFilter .None ) then sup.markUsed() // invalid suppressions, don't report as unused
123
128
124
129
def addSuppression (sup : Suppression ): Unit =
125
130
val suppressions = mySuppressions.getOrElseUpdate(sup.annotPos.source, ListBuffer .empty)
126
- if sup.start != sup.end && suppressions.forall(x => x.start != sup.start || x.end != sup.end) then
131
+ if sup.start != sup.end then
127
132
suppressions += sup
128
133
129
134
def reportSuspendedMessages (source : SourceFile )(using Context ): Unit = {
@@ -134,18 +139,25 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
134
139
mySuspendedMessages.remove(source).foreach(_.foreach(ctx.reporter.issueIfNotSuppressed))
135
140
}
136
141
137
- def runFinished (hasErrors : Boolean ): Unit =
142
+ def runFinished ()(using Context ): Unit =
143
+ val hasErrors = ctx.reporter.hasErrors
138
144
// report suspended messages (in case the run finished before typer)
139
145
mySuspendedMessages.keysIterator.toList.foreach(reportSuspendedMessages)
140
146
// report unused nowarns only if all all phases are done
141
147
if ! hasErrors && ctx.settings.WunusedHas .nowarn then
142
148
for
143
149
source <- mySuppressions.keysIterator.toList
144
150
sups <- mySuppressions.remove(source)
145
- sup <- sups.reverse
146
- if ! sup.used
147
151
do
148
- report.warning(" @nowarn annotation does not suppress any warnings" , sup.annotPos)
152
+ val suppressions = sups.reverse.toList
153
+ for sup <- suppressions do
154
+ if ! sup.used
155
+ && ! suppressions.exists(s => s.ne(sup) && s.used && s.annotPos == sup.annotPos) // duplicate
156
+ && sup.filters != List (MessageFilter .None ) // invalid suppression, don't report as unused
157
+ then
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
149
161
150
162
/** The compilation units currently being compiled, this may return different
151
163
* results over time.
@@ -411,7 +423,7 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
411
423
ctx.reporter.finalizeReporting()
412
424
if (! ctx.reporter.hasErrors)
413
425
Rewrites .writeBack()
414
- suppressions.runFinished(hasErrors = ctx.reporter.hasErrors )
426
+ suppressions.runFinished()
415
427
while (finalizeActions.nonEmpty && canProgress()) {
416
428
val action = finalizeActions.remove(0 )
417
429
action()
0 commit comments