@@ -15,7 +15,7 @@ import core._
15
15
import Flags ._
16
16
import Contexts ._
17
17
import Names ._
18
- import NameKinds .WildcardParamName
18
+ import NameKinds .{ WildcardParamName , QualifiedName }
19
19
import NameOps ._
20
20
import ast .{Positioned , Trees }
21
21
import ast .Trees ._
@@ -30,7 +30,7 @@ import scala.annotation.tailrec
30
30
import rewrites .Rewrites .{patch , overlapsPatch }
31
31
import reporting ._
32
32
import config .Feature
33
- import config .Feature .{sourceVersion , migrateTo3 }
33
+ import config .Feature .{sourceVersion , migrateTo3 , globalOnlyImports }
34
34
import config .SourceVersion ._
35
35
import config .SourceVersion
36
36
@@ -3307,23 +3307,25 @@ object Parsers {
3307
3307
in.languageImportContext = in.languageImportContext.importContext(imp, NoSymbol )
3308
3308
for
3309
3309
case ImportSelector (id @ Ident (imported), EmptyTree , _) <- selectors
3310
- if allSourceVersionNames.contains(imported)
3311
3310
do
3312
- if ! outermost then
3313
- syntaxError(i " source version import is only allowed at the toplevel " , id.span)
3314
- else if ctx.compilationUnit.sourceVersion.isDefined then
3315
- syntaxError(i " duplicate source version import " , id.span)
3316
- else if illegalSourceVersionNames.contains(imported) then
3317
- val candidate =
3318
- val nonMigration = imported.toString.replace(" -migration" , " " )
3319
- validSourceVersionNames.find(_.show == nonMigration)
3320
- val baseMsg = i " ` $imported` is not a valid source version "
3321
- val msg = candidate match
3322
- case Some (member) => i " $baseMsg, did you mean language.` $member`? "
3323
- case _ => baseMsg
3324
- syntaxError(msg, id.span)
3325
- else
3326
- ctx.compilationUnit.sourceVersion = Some (SourceVersion .valueOf(imported.toString))
3311
+ if globalOnlyImports.contains(QualifiedName (prefix, imported.asTermName)) && ! outermost then
3312
+ syntaxError(i " this language import is only allowed at the toplevel " , id.span)
3313
+ if allSourceVersionNames.contains(imported) && prefix.isEmpty then
3314
+ if ! outermost then
3315
+ syntaxError(i " source version import is only allowed at the toplevel " , id.span)
3316
+ else if ctx.compilationUnit.sourceVersion.isDefined then
3317
+ syntaxError(i " duplicate source version import " , id.span)
3318
+ else if illegalSourceVersionNames.contains(imported) then
3319
+ val candidate =
3320
+ val nonMigration = imported.toString.replace(" -migration" , " " )
3321
+ validSourceVersionNames.find(_.show == nonMigration)
3322
+ val baseMsg = i " ` $imported` is not a valid source version "
3323
+ val msg = candidate match
3324
+ case Some (member) => i " $baseMsg, did you mean language.` $member`? "
3325
+ case _ => baseMsg
3326
+ syntaxError(msg, id.span)
3327
+ else
3328
+ ctx.compilationUnit.sourceVersion = Some (SourceVersion .valueOf(imported.toString))
3327
3329
case None =>
3328
3330
imp
3329
3331
0 commit comments