Skip to content

Commit

Permalink
Move root package name check to Typer
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 8, 2023
1 parent 990d112 commit 052afd8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
13 changes: 1 addition & 12 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,6 @@ object Parsers {
nme.ERROR
}

def checkNotRoot(name: Name): name.type =
if name == nme.ROOTPKG then syntaxError(em"Illegal use of root package name.")
name

/** Accept identifier and return Ident with its name as a term name. */
def termIdent(): Ident =
makeIdent(in.token, in.offset, ident())
Expand Down Expand Up @@ -3602,13 +3598,6 @@ object Parsers {
case _ =>
first :: Nil
}

def checkForRoot(trees: List[Tree]): Unit = for tree <- trees do tree match
case IdPattern(id, _) => checkNotRoot(id.name)
case Tuple(trees) => checkForRoot(trees)
case _ =>
checkForRoot(lhs)

val tpt = typedOpt()
val rhs =
if tpt.isEmpty || in.token == EQUALS then
Expand Down Expand Up @@ -3689,7 +3678,7 @@ object Parsers {
else {
val mods1 = addFlag(mods, Method)
val ident = termIdent()
var name = checkNotRoot(ident.name).asTermName
var name = ident.name.asTermName
val paramss =
if in.featureEnabled(Feature.clauseInterleaving) then
// If you are making interleaving stable manually, please refer to the PR introducing it instead, section "How to make non-experimental"
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

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

0 comments on commit 052afd8

Please sign in to comment.