@@ -12,6 +12,7 @@ import ast.tpd
1212
1313class CrossVersionChecks extends MiniPhase :
1414 import tpd .*
15+ import CrossVersionChecks .*
1516
1617 override def phaseName : String = CrossVersionChecks .name
1718
@@ -27,7 +28,7 @@ class CrossVersionChecks extends MiniPhase:
2728 // arbitrarily choose one as more important than the other.
2829 private def checkUndesiredProperties (sym : Symbol , pos : SrcPos )(using Context ): Unit =
2930 checkDeprecated(sym, pos)
30- checkExperimental (sym, pos)
31+ checkExperimentalRef (sym, pos)
3132 checkSinceAnnot(sym, pos)
3233
3334 val xMigrationValue = ctx.settings.Xmigration .value
@@ -69,10 +70,6 @@ class CrossVersionChecks extends MiniPhase:
6970 val since = annot.argumentConstant(1 ).map(" since " + _.stringValue).getOrElse(" " )
7071 report.deprecationWarning(s " ${sym.showLocated} is deprecated ${since}${msg}" , pos)
7172
72- private def checkExperimental (sym : Symbol , pos : SrcPos )(using Context ): Unit =
73- if sym.isExperimental && ! ctx.owner.isInExperimentalScope then
74- Feature .checkExperimentalDef(sym, pos)
75-
7673 private def checkExperimentalSignature (sym : Symbol , pos : SrcPos )(using Context ): Unit =
7774 class Checker extends TypeTraverser :
7875 def traverse (tp : Type ): Unit =
@@ -192,11 +189,11 @@ class CrossVersionChecks extends MiniPhase:
192189 tpe.foreachPart {
193190 case TypeRef (_, sym : Symbol ) =>
194191 checkDeprecated(sym, tree.srcPos)
195- checkExperimental (sym, tree.srcPos)
192+ checkExperimentalRef (sym, tree.srcPos)
196193 checkSinceAnnot(sym, tree.srcPos)
197194 case TermRef (_, sym : Symbol ) =>
198195 checkDeprecated(sym, tree.srcPos)
199- checkExperimental (sym, tree.srcPos)
196+ checkExperimentalRef (sym, tree.srcPos)
200197 checkSinceAnnot(sym, tree.srcPos)
201198 case _ =>
202199 }
@@ -214,3 +211,10 @@ end CrossVersionChecks
214211object CrossVersionChecks :
215212 val name : String = " crossVersionChecks"
216213 val description : String = " check issues related to deprecated and experimental"
214+
215+ /** Check that a reference to an experimental definition with symbol `sym` is only
216+ * used in an experimental scope
217+ */
218+ def checkExperimentalRef (sym : Symbol , pos : SrcPos )(using Context ): Unit =
219+ if sym.isExperimental && ! ctx.owner.isInExperimentalScope then
220+ Feature .checkExperimentalDef(sym, pos)
0 commit comments