@@ -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
@@ -118,12 +125,10 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
118125 .merge
119126 addSuppression :
120127 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
123128
124129 def addSuppression (sup : Suppression ): Unit =
125130 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
127132 suppressions += sup
128133
129134 def reportSuspendedMessages (source : SourceFile )(using Context ): Unit = {
@@ -134,18 +139,25 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
134139 mySuspendedMessages.remove(source).foreach(_.foreach(ctx.reporter.issueIfNotSuppressed))
135140 }
136141
137- def runFinished (hasErrors : Boolean ): Unit =
142+ def runFinished ()(using Context ): Unit =
143+ val hasErrors = ctx.reporter.hasErrors
138144 // report suspended messages (in case the run finished before typer)
139145 mySuspendedMessages.keysIterator.toList.foreach(reportSuspendedMessages)
140146 // report unused nowarns only if all all phases are done
141147 if ! hasErrors && ctx.settings.WunusedHas .nowarn then
142148 for
143149 source <- mySuppressions.keysIterator.toList
144150 sups <- mySuppressions.remove(source)
145- sup <- sups.reverse
146- if ! sup.used
147151 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
149161
150162 /** The compilation units currently being compiled, this may return different
151163 * results over time.
@@ -411,7 +423,7 @@ extends ImplicitRunInfo, ConstraintRunInfo, cc.CaptureRunInfo {
411423 ctx.reporter.finalizeReporting()
412424 if (! ctx.reporter.hasErrors)
413425 Rewrites .writeBack()
414- suppressions.runFinished(hasErrors = ctx.reporter.hasErrors )
426+ suppressions.runFinished()
415427 while (finalizeActions.nonEmpty && canProgress()) {
416428 val action = finalizeActions.remove(0 )
417429 action()
0 commit comments