Skip to content

Commit 1d0c050

Browse files
committed
Suppression matches inlined positions
The inlined stack includes the nonInlined pos itself, which is filtered by rendering.
1 parent 8f70097 commit 1d0c050

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ trait MessageRendering {
3030
def stripColor(str: String): String =
3131
str.replaceAll("\u001b\\[.*?m", "")
3232

33-
/** List of all the inline calls that surround the position */
34-
def inlinePosStack(pos: SourcePosition): List[SourcePosition] =
35-
if pos.outer != null && pos.outer.exists then pos :: inlinePosStack(pos.outer)
36-
else Nil
37-
3833
/** Get the sourcelines before and after the position, as well as the offset
3934
* for rendering line numbers
4035
*
@@ -240,7 +235,7 @@ trait MessageRendering {
240235
def messageAndPos(dia: Diagnostic)(using Context): String = {
241236
import dia.*
242237
val pos1 = pos.nonInlined
243-
val inlineStack = inlinePosStack(pos).filter(_ != pos1)
238+
val inlineStack = pos.inlinePosStack.filter(_ != pos1)
244239
val maxLineNumber =
245240
if pos.exists then (pos1 :: inlineStack).map(_.endLine).max + 1
246241
else 0

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,10 @@ class Suppression(val annotPos: SourcePosition, val filters: List[MessageFilter]
150150
_used = supersededState
151151
def matches(dia: Diagnostic): Boolean =
152152
val pos = dia.pos
153-
pos.exists && start <= pos.start && pos.end <= end && filters.forall(_.matches(dia))
153+
def posMatches =
154+
start <= pos.start && pos.end <= end
155+
|| pos.inlinePosStack.exists(p => start <= p.start && p.end <= end)
156+
pos.exists && posMatches && filters.forall(_.matches(dia))
154157

155158
override def toString = s"Suppress in ${annotPos.source} $start..$end [${filters.mkString(", ")}]"
156159
end Suppression

compiler/src/dotty/tools/dotc/util/SourcePosition.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import scala.annotation.internal.sharable
1111

1212
/** A source position is comprised of a span and a source file */
1313
case class SourcePosition(source: SourceFile, span: Span, outer: SourcePosition = NoSourcePosition)
14-
extends SrcPos, interfaces.SourcePosition, Showable {
14+
extends SrcPos, interfaces.SourcePosition, Showable:
1515

1616
def sourcePos(using Context) = this
1717

@@ -82,7 +82,14 @@ extends SrcPos, interfaces.SourcePosition, Showable {
8282
s"${if (source.exists) source.file.toString else "(no source)"}:$span"
8383

8484
def toText(printer: Printer): Text = printer.toText(this)
85-
}
85+
86+
object SourcePosition:
87+
extension (pos: SourcePosition)
88+
/** List of all the inline calls that surround the position. */
89+
def inlinePosStack: List[SourcePosition] =
90+
if pos.outer != null && pos.outer.exists then pos :: pos.outer.inlinePosStack
91+
else pos :: Nil
92+
end SourcePosition
8693

8794
/** A sentinel for a non-existing source position */
8895
@sharable object NoSourcePosition extends SourcePosition(NoSource, NoSpan) {

tests/warn/i24082.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -deprecation -Werror
2+
3+
import annotation.*
4+
5+
@deprecated
6+
case object A {
7+
inline def use: Any = A
8+
}
9+
10+
@nowarn
11+
object test {
12+
A.use
13+
}

0 commit comments

Comments
 (0)