Skip to content

Commit e0ff162

Browse files
committed
Refactoring: move experimental imports checking to Checking.scala
1 parent aa2f544 commit e0ff162

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import Decorators._
1313
import Symbols._, SymUtils._, NameOps._
1414
import ContextFunctionResults.annotateContextResults
1515
import config.Printers.typr
16-
import config.Feature
1716
import reporting._
1817

1918
object PostTyper {
@@ -449,30 +448,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
449448
throw ex
450449
}
451450

452-
/** In addition to normal processing, check that experimental language
453-
* imports are done only in experimental scopes, or in scopes where
454-
* all statements are @experimental definitions.
455-
*/
456451
override def transformStats(trees: List[Tree], exprOwner: Symbol)(using Context): List[Tree] =
457-
458-
def onlyExperimentalDefs = trees.forall {
459-
case _: Import | EmptyTree => true
460-
case stat: MemberDef => stat.symbol.isExperimental
461-
case _ => false
462-
}
463-
464-
def checkExperimentalImports =
465-
for case imp @ Import(qual, selectors) <- trees do
466-
languageImport(qual) match
467-
case Some(nme.experimental)
468-
if !ctx.owner.isInExperimentalScope && !onlyExperimentalDefs
469-
&& selectors.exists(sel => Feature.experimental(sel.name) != Feature.scala2macros) =>
470-
Feature.checkExperimentalFeature("features", imp.srcPos)
471-
case _ =>
472-
473452
try super.transformStats(trees, exprOwner)
474-
finally checkExperimentalImports
475-
end transformStats
453+
finally Checking.checkExperimentalImports(trees)
476454

477455
/** Transforms the rhs tree into a its default tree if it is in an `erased` val/def.
478456
* Performed to shrink the tree that is known to be erased later.

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,24 @@ object Checking {
719719
checkValue(tree)
720720
case _ =>
721721
tree
722+
723+
/** Check that experimental language imports in `trees`
724+
* are done only in experimental scopes, or in scopes where
725+
* all statements are @experimental definitions.
726+
*/
727+
def checkExperimentalImports(trees: List[Tree])(using Context): Unit =
728+
def onlyExperimentalDefs = trees.forall {
729+
case _: Import | EmptyTree => true
730+
case stat: MemberDef => stat.symbol.isExperimental
731+
case _ => false
732+
}
733+
for case imp @ Import(qual, selectors) <- trees do
734+
languageImport(qual) match
735+
case Some(nme.experimental)
736+
if !ctx.owner.isInExperimentalScope && !onlyExperimentalDefs
737+
&& selectors.exists(sel => experimental(sel.name) != scala2macros) =>
738+
checkExperimentalFeature("features", imp.srcPos)
739+
case _ =>
722740
}
723741

724742
trait Checking {
@@ -830,6 +848,7 @@ trait Checking {
830848
em"Implementation restriction: ${path.tpe.classSymbol} is not a valid prefix " +
831849
"for a wildcard export, as it is a package.", path.srcPos)
832850

851+
833852
/** Check that module `sym` does not clash with a class of the same name
834853
* that is concurrently compiled in another source file.
835854
*/

0 commit comments

Comments
 (0)