@@ -2472,7 +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)
2475+ checkNonRootName(vdef.name , vdef.nameSpan )
24762476 completeAnnotations(vdef, sym)
24772477 if (sym.isOneOf(GivenOrImplicit )) checkImplicitConversionDefOK(sym)
24782478 if sym.is(Module ) then checkNoModuleClash(sym)
@@ -2506,7 +2506,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25062506 // hence we special case it until `erased` is no longer experimental.
25072507 sym.setFlag(Erased )
25082508 val DefDef (name, paramss, tpt, _) = ddef
2509- if name == nme. ROOTPKG then report.error( em " Illegal use of root package name. " , ddef)
2509+ checkNonRootName(ddef.name , ddef.nameSpan )
25102510 completeAnnotations(ddef, sym)
25112511 val paramss1 = paramss.nestedMapConserve(typed(_)).asInstanceOf [List [ParamClause ]]
25122512 for case ValDefs (vparams) <- paramss1 do
@@ -2855,6 +2855,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
28552855 val pkg = pid1.symbol
28562856 pid1 match
28572857 case pid1 : RefTree if pkg.is(Package ) =>
2858+ if ctx.owner != defn.EmptyPackageClass then
2859+ checkNonRootName(pid1.name, pid1.span)
28582860 inContext(ctx.packageContext(tree, pkg)) {
28592861 // If it exists, complete the class containing the top-level definitions
28602862 // before typing any statement in the package to avoid cycles as in i13669.scala
0 commit comments