@@ -821,29 +821,39 @@ object Checking {
821
821
case Nil =>
822
822
Nil
823
823
824
- for case imp @ Import (qual, selectors) <- trees do
824
+ def unitExperimentalLanguageImports =
825
825
def isAllowedImport (sel : untpd.ImportSelector ) =
826
826
val name = Feature .experimental(sel.name)
827
827
name == Feature .scala2macros
828
828
|| name == Feature .captureChecking
829
+ trees.filter {
830
+ case Import (qual, selectors) =>
831
+ languageImport(qual) match
832
+ case Some (nme.experimental) =>
833
+ ! selectors.forall(isAllowedImport) && ! ctx.owner.isInExperimentalScope
834
+ case _ => false
835
+ case _ => false
836
+ }
829
837
830
- languageImport(qual) match
831
- case Some (nme.experimental)
832
- if ! ctx.owner.isInExperimentalScope && ! selectors.forall(isAllowedImport) =>
833
- if ctx.owner.is(Package ) || ctx.owner.name.startsWith(str.REPL_SESSION_LINE ) then
834
- // mark all top-level definitions as @experimental
835
- for tree <- nonExperimentalStats(trees) do
836
- tree match
837
- case tree : MemberDef =>
838
- // TODO move this out of checking (into posttyper?)
839
- val sym = tree.symbol
840
- if ! sym.isExperimental then
841
- sym.addAnnotation(ExperimentalAnnotation (i " Added by top level $imp" , sym.span))
842
- case tree =>
843
- // There is no definition to attach the @experimental annotation
844
- report.error(" Implementation restriction: top-level `val _ = ...` is not supported with experimental language imports." , tree.srcPos)
845
- else Feature .checkExperimentalFeature(" feature local import" , imp.srcPos)
838
+ if ctx.owner.is(Package ) || ctx.owner.name.startsWith(str.REPL_SESSION_LINE ) then
839
+ unitExperimentalLanguageImports match
840
+ case imp :: _ =>
841
+ // mark all top-level definitions as @experimental
842
+ for tree <- nonExperimentalStats(trees) do
843
+ tree match
844
+ case tree : MemberDef =>
845
+ // TODO move this out of checking (into posttyper?)
846
+ val sym = tree.symbol
847
+ if ! sym.isExperimental then
848
+ sym.addAnnotation(ExperimentalAnnotation (i " Added by top level $imp" , sym.span))
849
+ case tree =>
850
+ // There is no definition to attach the @experimental annotation
851
+ report.error(" Implementation restriction: top-level `val _ = ...` is not supported with experimental language imports." , tree.srcPos)
846
852
case _ =>
853
+ else
854
+ for imp <- unitExperimentalLanguageImports do
855
+ Feature .checkExperimentalFeature(" feature local import" , imp.srcPos)
856
+
847
857
end checkAndAdaptExperimentalImports
848
858
849
859
/** Checks that PolyFunction only have valid refinements.
0 commit comments