diff --git a/compiler/src/dotty/tools/dotc/report.scala b/compiler/src/dotty/tools/dotc/report.scala index 7bc301184022..05020700f11b 100644 --- a/compiler/src/dotty/tools/dotc/report.scala +++ b/compiler/src/dotty/tools/dotc/report.scala @@ -21,7 +21,7 @@ object report: ctx.reporter.report(warning) def deprecationWarning(msg: Message, pos: SrcPos, origin: String = "")(using Context): Unit = - issueWarning(new DeprecationWarning(msg, pos.sourcePos, origin)) + issueWarning(DeprecationWarning(msg, addInlineds(pos), origin)) def migrationWarning(msg: Message, pos: SrcPos)(using Context): Unit = issueWarning(new MigrationWarning(msg, pos.sourcePos)) @@ -126,7 +126,9 @@ object report: private def addInlineds(pos: SrcPos)(using Context): SourcePosition = def recur(pos: SourcePosition, inlineds: List[Trees.Tree[?]]): SourcePosition = inlineds match - case inlined :: inlineds1 => pos.withOuter(recur(inlined.sourcePos, inlineds1)) + case inlined :: inlineds => + val outer = recur(inlined.sourcePos, inlineds) + pos.withOuter(outer) case Nil => pos recur(pos.sourcePos, tpd.enclosingInlineds) diff --git a/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala b/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala index ed96e3cacd4b..2122c10ad625 100644 --- a/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/CrossVersionChecks.scala @@ -78,7 +78,8 @@ class CrossVersionChecks extends MiniPhase: do val msg = annot.argumentConstantString(0).map(msg => s": $msg").getOrElse("") val since = annot.argumentConstantString(1).map(version => s" (since: $version)").getOrElse("") - report.deprecationWarning(em"inheritance from $psym is deprecated$since$msg", parent.srcPos, origin=psym.showFullName) + val composed = em"inheritance from $psym is deprecated$since$msg" + report.deprecationWarning(composed, parent.srcPos, origin = psym.showFullName) } override def transformValDef(tree: ValDef)(using Context): ValDef = @@ -166,16 +167,19 @@ object CrossVersionChecks: * Also check for deprecation of the companion class for synthetic methods in the companion module. */ private[CrossVersionChecks] def checkDeprecatedRef(sym: Symbol, pos: SrcPos)(using Context): Unit = - def maybeWarn(annotee: Symbol, annot: Annotation) = if !skipWarning(sym) then + def warn(annotee: Symbol, annot: Annotation) = val message = annot.argumentConstantString(0).filter(!_.isEmpty).map(": " + _).getOrElse("") val since = annot.argumentConstantString(1).filter(!_.isEmpty).map(" since " + _).getOrElse("") - report.deprecationWarning(em"${annotee.showLocated} is deprecated${since}${message}", pos, origin=annotee.showFullName) + val composed = em"${annotee.showLocated} is deprecated${since}${message}" + report.deprecationWarning(composed, pos, origin = annotee.showFullName) sym.getAnnotation(defn.DeprecatedAnnot) match - case Some(annot) => maybeWarn(sym, annot) + case Some(annot) => if !skipWarning(sym) then warn(sym, annot) case _ => if sym.isAllOf(SyntheticMethod) then val companion = sym.owner.companionClass - if companion.is(CaseClass) then companion.getAnnotation(defn.DeprecatedAnnot).foreach(maybeWarn(companion, _)) + if companion.is(CaseClass) then + for annot <- companion.getAnnotation(defn.DeprecatedAnnot) if !skipWarning(sym) do + warn(companion, annot) /** Decide whether the deprecation of `sym` should be ignored in this context. * diff --git a/compiler/src/dotty/tools/dotc/util/Spans.scala b/compiler/src/dotty/tools/dotc/util/Spans.scala index 7d4bbe0e8180..33346ad6da17 100644 --- a/compiler/src/dotty/tools/dotc/util/Spans.scala +++ b/compiler/src/dotty/tools/dotc/util/Spans.scala @@ -42,19 +42,19 @@ object Spans { /** The start of this span. */ def start: Int = { - assert(exists) + assert(exists, "start of NoSpan") (coords & StartEndMask).toInt } /** The end of this span */ def end: Int = { - assert(exists) + assert(exists, "end of NoSpan") ((coords >>> StartEndBits) & StartEndMask).toInt } /** The point of this span, returns start for synthetic spans */ def point: Int = { - assert(exists) + assert(exists, "point of NoSpan") val poff = pointDelta if (poff == SyntheticPointDelta) start else start + poff } diff --git a/tests/warn/i22795.check b/tests/warn/i22795.check new file mode 100644 index 000000000000..2ce9b16e0477 --- /dev/null +++ b/tests/warn/i22795.check @@ -0,0 +1,12 @@ + +-- Deprecation Warning: tests/warn/i22795/test_1.scala:4:7 ------------------------------------------------------------- +4 | lib.m() // warn + | ^^^^^^^ + | object A is deprecated + |--------------------------------------------------------------------------------------------------------------------- + |Inline stack trace + |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + |This location contains code that was inlined from test_1.scala:5 +5 | + | ^^^^^^^^ + --------------------------------------------------------------------------------------------------------------------- diff --git a/tests/warn/i22795/lib_0.scala b/tests/warn/i22795/lib_0.scala new file mode 100644 index 000000000000..13225a865dc4 --- /dev/null +++ b/tests/warn/i22795/lib_0.scala @@ -0,0 +1,11 @@ + +import scala.quoted._ + +@deprecated object A + +object lib: + inline def m() = ${mImpl} + + def mImpl(using Quotes): Expr[Any] = + import quotes.reflect._ + Ref(Symbol.classSymbol("A$").companionModule).asExpr diff --git a/tests/warn/i22795/test_1.scala b/tests/warn/i22795/test_1.scala new file mode 100644 index 000000000000..e75ca03d5cf6 --- /dev/null +++ b/tests/warn/i22795/test_1.scala @@ -0,0 +1,4 @@ +//> using options -deprecation + +@main def Test = println: + lib.m() // warn