@@ -1626,16 +1626,16 @@ class Typer extends Namer
1626
1626
def typedPackageDef (tree : untpd.PackageDef )(implicit ctx : Context ): Tree = track(" typedPackageDef" ) {
1627
1627
val pid1 = typedExpr(tree.pid, AnySelectionProto )(ctx.addMode(Mode .InPackageClauseName ))
1628
1628
val pkg = pid1.symbol
1629
-
1630
- // Package will not exist if a duplicate type has already been entered, see
1631
- // `tests/neg/1708.scala`, else branch's error message should be supressed
1632
- if (pkg.exists) {
1633
- if (! pkg.is(Package )) ctx.error(PackageNameAlreadyDefined (pkg), tree.pos)
1634
- val packageCtx = ctx.packageContext(tree, pkg)
1635
- val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageCtx)
1636
- cpy.PackageDef (tree)(pid1.asInstanceOf [RefTree ], stats1) withType pkg.termRef
1629
+ pid1 match {
1630
+ case pid1 : RefTree if pkg.exists =>
1631
+ if (! pkg.is(Package )) ctx.error(PackageNameAlreadyDefined (pkg), tree.pos)
1632
+ val packageCtx = ctx.packageContext(tree, pkg)
1633
+ val stats1 = typedStats(tree.stats, pkg.moduleClass)(packageCtx)
1634
+ cpy.PackageDef (tree)(pid1, stats1).withType(pkg.termRef)
1635
+ case _ =>
1636
+ // Package will not exist if a duplicate type has already been entered, see `tests/neg/1708.scala`
1637
+ errorTree(tree, i " package ${tree.pid.name} does not exist " )
1637
1638
}
1638
- else errorTree(tree, i " package ${tree.pid.name} does not exist " )
1639
1639
}
1640
1640
1641
1641
def typedAnnotated (tree : untpd.Annotated , pt : Type )(implicit ctx : Context ): Tree = track(" typedAnnotated" ) {
0 commit comments