File tree Expand file tree Collapse file tree 2 files changed +14
-9
lines changed
src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -351,7 +351,7 @@ class Namer { typer: Typer =>
351
351
val existingTpe = pkgOwner.info.decls.lookup(pid.name.toTypeName)
352
352
if (existingTpe != NoSymbol ) {
353
353
ctx.error(PkgDuplicateSymbol (existingTpe), pid.pos)
354
- ctx.newCompletePackageSymbol(pkgOwner, (pid.name.asTermName.show + " $$package " ).toTermName).entered
354
+ ctx.newCompletePackageSymbol(pkgOwner, (pid.name ++ " $termDup " ).toTermName).entered
355
355
}
356
356
else ctx.newCompletePackageSymbol(pkgOwner, pid.name.asTermName).entered
357
357
}
Original file line number Diff line number Diff line change @@ -1341,14 +1341,19 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1341
1341
def typedPackageDef (tree : untpd.PackageDef )(implicit ctx : Context ): Tree = track(" typedPackageDef" ) {
1342
1342
val pid1 = typedExpr(tree.pid, AnySelectionProto )(ctx.addMode(Mode .InPackageClauseName ))
1343
1343
val pkg = pid1.symbol
1344
- val packageContext =
1345
- if (pkg is Package ) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)
1346
- else {
1347
- ctx.error(em " $pkg is already defined, cannot be a package " , tree.pos)
1348
- ctx
1349
- }
1350
- val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageContext)
1351
- cpy.PackageDef (tree)(pid1.asInstanceOf [RefTree ], stats1) withType pkg.valRef
1344
+
1345
+ // Package will not exist if a duplicate type has already been entered, see
1346
+ // `tests/neg/1708.scala`, else branch's error message should be supressed
1347
+ if (pkg.exists) {
1348
+ val packageContext =
1349
+ if (pkg is Package ) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)
1350
+ else {
1351
+ ctx.error(em " $pkg is already defined, cannot be a package " , tree.pos)
1352
+ ctx
1353
+ }
1354
+ val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageContext)
1355
+ cpy.PackageDef (tree)(pid1.asInstanceOf [RefTree ], stats1) withType pkg.valRef
1356
+ } else errorTree(tree, i " package ${tree.pid.name} does not exist " )
1352
1357
}
1353
1358
1354
1359
def typedAnnotated (tree : untpd.Annotated , pt : Type )(implicit ctx : Context ): Tree = track(" typedAnnotated" ) {
You can’t perform that action at this time.
0 commit comments