Skip to content

Commit 3bf39e1

Browse files
committed
Refactoring: move experimental imports checking to Checking.scala
1 parent 33f901f commit 3bf39e1

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
@@ -721,6 +721,24 @@ object Checking {
721721
checkValue(tree)
722722
case _ =>
723723
tree
724+
725+
/** Check that experimental language imports in `trees`
726+
* are done only in experimental scopes, or in scopes where
727+
* all statements are @experimental definitions.
728+
*/
729+
def checkExperimentalImports(trees: List[Tree])(using Context): Unit =
730+
def onlyExperimentalDefs = trees.forall {
731+
case _: Import | EmptyTree => true
732+
case stat: MemberDef => stat.symbol.isExperimental
733+
case _ => false
734+
}
735+
for case imp @ Import(qual, selectors) <- trees do
736+
languageImport(qual) match
737+
case Some(nme.experimental)
738+
if !ctx.owner.isInExperimentalScope && !onlyExperimentalDefs
739+
&& selectors.exists(sel => experimental(sel.name) != scala2macros) =>
740+
checkExperimentalFeature("features", imp.srcPos)
741+
case _ =>
724742
}
725743

726744
trait Checking {
@@ -832,6 +850,7 @@ trait Checking {
832850
em"Implementation restriction: ${path.tpe.classSymbol} is not a valid prefix " +
833851
"for a wildcard export, as it is a package.", path.srcPos)
834852

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

0 commit comments

Comments
 (0)