Skip to content

Commit 9315c4a

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

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -449,30 +449,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
449449
throw ex
450450
}
451451

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-
*/
456452
override def transformStats(trees: List[Tree], exprOwner: Symbol)(using Context): List[Tree] =
457453

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-
473454
try super.transformStats(trees, exprOwner)
474-
finally checkExperimentalImports
475-
end transformStats
455+
finally Checking.checkExperimentalImports(trees)
476456

477457
/** Transforms the rhs tree into a its default tree if it is in an `erased` val/def.
478458
* 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)