@@ -11,17 +11,16 @@ import util.Spans._
1111import util .{Store , SourcePosition }
1212import scala .collection .{ mutable , immutable }
1313import ast ._
14- import Trees ._
1514import MegaPhase ._
1615import config .Printers .{checks , noPrinter }
17- import scala .util .Failure
18- import config .NoScalaVersion
16+ import scala .util .{ Try , Failure , Success }
17+ import config .{ ScalaVersion , NoScalaVersion }
1918import Decorators ._
2019import typer .ErrorReporting ._
2120import config .Feature .warnOnMigration
2221
2322object RefChecks {
24- import tpd ._
23+ import tpd .{ Tree , MemberDef }
2524 import reporting .messages ._
2625
2726 val name : String = " refchecks"
@@ -817,24 +816,39 @@ object RefChecks {
817816 // I assume that's a consequence of some code trying to avoid noise by suppressing
818817 // warnings after the first, but I think it'd be better if we didn't have to
819818 // arbitrarily choose one as more important than the other.
820- private def checkUndesiredProperties (sym : Symbol , pos : SourcePosition )(using Context ): Unit = {
821- // If symbol is deprecated, and the point of reference is not enclosed
822- // in either a deprecated member or a scala bridge method, issue a warning.
823- if (sym.isDeprecated && ! ctx.owner.ownersIterator.exists(_.isDeprecated))
824- ctx.deprecationWarning(" %s is deprecated%s" .format(
825- sym.showLocated, sym.deprecationMessage map (" : " + _) getOrElse " " ), pos)
826- // Similar to deprecation: check if the symbol is marked with @migration
827- // indicating it has changed semantics between versions.
819+ private def checkUndesiredProperties (sym : Symbol , pos : SourcePosition )(using Context ): Unit =
820+ checkDeprecated(sym, pos)
821+
828822 val xMigrationValue = ctx.settings.Xmigration .value
829- if (sym.hasAnnotation(defn.MigrationAnnot ) && xMigrationValue != NoScalaVersion )
830- sym.migrationVersion.get match {
831- case scala.util.Success (symVersion) if xMigrationValue < symVersion=>
832- ctx.warning(SymbolChangedSemanticsInVersion (sym, symVersion), pos)
823+ if xMigrationValue != NoScalaVersion then
824+ checkMigration(sym, pos, xMigrationValue)
825+
826+
827+ /** If @deprecated is present, and the point of reference is not enclosed
828+ * in either a deprecated member or a scala bridge method, issue a warning.
829+ */
830+ private def checkDeprecated (sym : Symbol , pos : SourcePosition )(using Context ): Unit =
831+ for
832+ annot <- sym.getAnnotation(defn.DeprecatedAnnot )
833+ if ! ctx.owner.ownersIterator.exists(_.isDeprecated)
834+ do
835+ val msg = annot.argumentConstant(0 ).map(" : " + _.stringValue).getOrElse(" " )
836+ val since = annot.argumentConstant(1 ).map(" since " + _.stringValue).getOrElse(" " )
837+ ctx.deprecationWarning(s " ${sym.showLocated} is deprecated ${since}${msg}" , pos)
838+
839+ /** If @migration is present (indicating that the symbol has changed semantics between versions),
840+ * emit a warning.
841+ */
842+ private def checkMigration (sym : Symbol , pos : SourcePosition , xMigrationValue : ScalaVersion )(using Context ): Unit =
843+ for annot <- sym.getAnnotation(defn.MigrationAnnot ) do
844+ val migrationVersion = ScalaVersion .parse(annot.argumentConstant(1 ).get.stringValue)
845+ migrationVersion match
846+ case Success (symVersion) if xMigrationValue < symVersion =>
847+ val msg = annot.argumentConstant(0 ).get.stringValue
848+ ctx.warning(SymbolChangedSemanticsInVersion (sym, symVersion, msg), pos)
833849 case Failure (ex) =>
834- ctx.warning(SymbolHasUnparsableVersionNumber (sym, ex.getMessage() ), pos)
850+ ctx.warning(SymbolHasUnparsableVersionNumber (sym, ex.getMessage), pos)
835851 case _ =>
836- }
837- }
838852
839853 /** Check that a deprecated val or def does not override a
840854 * concrete, non-deprecated method. If it does, then
0 commit comments