Skip to content

Commit 052afd8

Browse files
committed
Move root package name check to Typer
1 parent 990d112 commit 052afd8

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,6 @@ object Parsers {
10711071
nme.ERROR
10721072
}
10731073

1074-
def checkNotRoot(name: Name): name.type =
1075-
if name == nme.ROOTPKG then syntaxError(em"Illegal use of root package name.")
1076-
name
1077-
10781074
/** Accept identifier and return Ident with its name as a term name. */
10791075
def termIdent(): Ident =
10801076
makeIdent(in.token, in.offset, ident())
@@ -3602,13 +3598,6 @@ object Parsers {
36023598
case _ =>
36033599
first :: Nil
36043600
}
3605-
3606-
def checkForRoot(trees: List[Tree]): Unit = for tree <- trees do tree match
3607-
case IdPattern(id, _) => checkNotRoot(id.name)
3608-
case Tuple(trees) => checkForRoot(trees)
3609-
case _ =>
3610-
checkForRoot(lhs)
3611-
36123601
val tpt = typedOpt()
36133602
val rhs =
36143603
if tpt.isEmpty || in.token == EQUALS then
@@ -3689,7 +3678,7 @@ object Parsers {
36893678
else {
36903679
val mods1 = addFlag(mods, Method)
36913680
val ident = termIdent()
3692-
var name = checkNotRoot(ident.name).asTermName
3681+
var name = ident.name.asTermName
36933682
val paramss =
36943683
if in.featureEnabled(Feature.clauseInterleaving) then
36953684
// If you are making interleaving stable manually, please refer to the PR introducing it instead, section "How to make non-experimental"

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,6 +2472,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
24722472

24732473
def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree = {
24742474
val ValDef(name, tpt, _) = vdef
2475+
if name == nme.ROOTPKG then report.error(em"Illegal use of root package name.", vdef)
24752476
completeAnnotations(vdef, sym)
24762477
if (sym.isOneOf(GivenOrImplicit)) checkImplicitConversionDefOK(sym)
24772478
if sym.is(Module) then checkNoModuleClash(sym)
@@ -2505,6 +2506,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25052506
// hence we special case it until `erased` is no longer experimental.
25062507
sym.setFlag(Erased)
25072508
val DefDef(name, paramss, tpt, _) = ddef
2509+
if name == nme.ROOTPKG then report.error(em"Illegal use of root package name.", ddef)
25082510
completeAnnotations(ddef, sym)
25092511
val paramss1 = paramss.nestedMapConserve(typed(_)).asInstanceOf[List[ParamClause]]
25102512
for case ValDefs(vparams) <- paramss1 do

0 commit comments

Comments
 (0)