aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2016-11-17 17:17:38 +0100
committerGitHub <noreply@github.com>2016-11-17 17:17:38 +0100
commitdd0db48342b3ccc773373870f36348de846c66e4 (patch)
treef570ca1d762dc7d04ad61d808ae7bd5ca19454c9 /src/dotty/tools/dotc/typer/Typer.scala
parent156a9d978c9dab8e63ce1677a8743487057533ba (diff)
parent040379e2d5a77722563d73723044e065f2c1632b (diff)
downloaddotty-dd0db48342b3ccc773373870f36348de846c66e4.tar.gz
dotty-dd0db48342b3ccc773373870f36348de846c66e4.tar.bz2
dotty-dd0db48342b3ccc773373870f36348de846c66e4.zip
Merge pull request #1722 from dotty-staging/topic/fix#1708
Fix #1708: duplicate symbols in package
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 667e1f82e..0ee9a2799 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") {