@@ -911,6 +911,7 @@ object RefChecks {
911911 private def checkUndesiredProperties (sym : Symbol , pos : SrcPos )(using Context ): Unit =
912912 checkDeprecated(sym, pos)
913913 checkExperimental(sym, pos)
914+ checkSinceAnnot(sym, pos)
914915
915916 val xMigrationValue = ctx.settings.Xmigration .value
916917 if xMigrationValue != NoScalaVersion then
@@ -970,6 +971,21 @@ object RefChecks {
970971 for annot <- sym.annotations if annot.symbol.isExperimental do
971972 Feature .checkExperimentalDef(annot.symbol, annot.tree)
972973
974+ private def checkSinceAnnot (sym : Symbol , pos : SrcPos )(using Context ): Unit =
975+ for
976+ annot <- sym.getAnnotation(defn.SinceAnnot )
977+ version <- annot.argumentConstantString(0 )
978+ do
979+ val releaseVersion = ctx.settings.scalaRelease.value
980+ ScalaVersion .parse(version) match
981+ case Success (symVersion) if symVersion > ctx.settings.scalaRelease.value =>
982+ report.error(
983+ i " $sym was added in Scala $version, therefore it cannot be used in the code targeting Scala ${releaseVersion.unparse}" ,
984+ pos)
985+ case Failure (ex) =>
986+ report.warning(i " $sym has an unparsable version number: ${ex.getMessage}" , pos)
987+ case _ =>
988+
973989 /** If @migration is present (indicating that the symbol has changed semantics between versions),
974990 * emit a warning.
975991 */
0 commit comments