aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
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 /src/dotty/tools/dotc/typer/Typer.scala
parent17ef1d85a55f049fa1f21dd279e47d61fe3eaa8c (diff)
downloaddotty-e73397ff48a518ffa5c7b381d04e210f401ab4f9.tar.gz
dotty-e73397ff48a518ffa5c7b381d04e210f401ab4f9.tar.bz2
dotty-e73397ff48a518ffa5c7b381d04e210f401ab4f9.zip
Fix #1708: return ErrorTree in `typedPackageDef` if pkg has no symbol
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 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") {