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