aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-16 17:27:42 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-11-17 10:04:24 +0100
commite73397ff48a518ffa5c7b381d04e210f401ab4f9 (patch)
treef14d437b17b7c1583b83568f1f4467998dc1027f
parent17ef1d85a55f049fa1f21dd279e47d61fe3eaa8c (diff)
downloaddotty-e73397ff48a518ffa5c7b381d04e210f401ab4f9.tar.gz
dotty-e73397ff48a518ffa5c7b381d04e210f401ab4f9.tar.bz2
dotty-e73397ff48a518ffa5c7b381d04e210f401ab4f9.zip
Fix #1708: return ErrorTree in `typedPackageDef` if pkg has no symbol
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala21
2 files changed, 14 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 9343597a4..51d7605c9 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -351,7 +351,7 @@ class Namer { typer: Typer =>
val existingTpe = pkgOwner.info.decls.lookup(pid.name.toTypeName)
if (existingTpe != NoSymbol) {
ctx.error(PkgDuplicateSymbol(existingTpe), pid.pos)
- ctx.newCompletePackageSymbol(pkgOwner, (pid.name.asTermName.show + "$$package").toTermName).entered
+ ctx.newCompletePackageSymbol(pkgOwner, (pid.name ++ "$termDup").toTermName).entered
}
else ctx.newCompletePackageSymbol(pkgOwner, pid.name.asTermName).entered
}
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index a93262314..55f4502b0 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -1341,14 +1341,19 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
def typedPackageDef(tree: untpd.PackageDef)(implicit ctx: Context): Tree = track("typedPackageDef") {
val pid1 = typedExpr(tree.pid, AnySelectionProto)(ctx.addMode(Mode.InPackageClauseName))
val pkg = pid1.symbol
- val packageContext =
- if (pkg is Package) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)
- else {
- ctx.error(em"$pkg is already defined, cannot be a package", tree.pos)
- ctx
- }
- val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageContext)
- cpy.PackageDef(tree)(pid1.asInstanceOf[RefTree], stats1) withType pkg.valRef
+
+ // Package will not exist if a duplicate type has already been entered, see
+ // `tests/neg/1708.scala`, else branch's error message should be supressed
+ if (pkg.exists) {
+ val packageContext =
+ if (pkg is Package) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)
+ else {
+ ctx.error(em"$pkg is already defined, cannot be a package", tree.pos)
+ ctx
+ }
+ val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageContext)
+ cpy.PackageDef(tree)(pid1.asInstanceOf[RefTree], stats1) withType pkg.valRef
+ } else errorTree(tree, i"package ${tree.pid.name} does not exist")
}
def typedAnnotated(tree: untpd.Annotated, pt: Type)(implicit ctx: Context): Tree = track("typedAnnotated") {