@@ -2472,7 +2472,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2472
2472
2473
2473
def typedValDef (vdef : untpd.ValDef , sym : Symbol )(using Context ): Tree = {
2474
2474
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 )
2476
2476
completeAnnotations(vdef, sym)
2477
2477
if (sym.isOneOf(GivenOrImplicit )) checkImplicitConversionDefOK(sym)
2478
2478
if sym.is(Module ) then checkNoModuleClash(sym)
@@ -2506,7 +2506,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2506
2506
// hence we special case it until `erased` is no longer experimental.
2507
2507
sym.setFlag(Erased )
2508
2508
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 )
2510
2510
completeAnnotations(ddef, sym)
2511
2511
val paramss1 = paramss.nestedMapConserve(typed(_)).asInstanceOf [List [ParamClause ]]
2512
2512
for case ValDefs (vparams) <- paramss1 do
@@ -2855,6 +2855,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2855
2855
val pkg = pid1.symbol
2856
2856
pid1 match
2857
2857
case pid1 : RefTree if pkg.is(Package ) =>
2858
+ if ctx.owner != defn.EmptyPackageClass then
2859
+ checkNonRootName(pid1.name, pid1.span)
2858
2860
inContext(ctx.packageContext(tree, pkg)) {
2859
2861
// If it exists, complete the class containing the top-level definitions
2860
2862
// before typing any statement in the package to avoid cycles as in i13669.scala
0 commit comments