From 17ef1d85a55f049fa1f21dd279e47d61fe3eaa8c Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Wed, 16 Nov 2016 15:45:03 +0100 Subject: Only issue error, no unlinking Unlinking proved to cause other problems in the typer, specifically if typechecking members of non-existing package or things referring to the unlinked package --- src/dotty/tools/dotc/reporting/diagnostic/messages.scala | 2 +- src/dotty/tools/dotc/typer/Namer.scala | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/dotty/tools') diff --git a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index a2557194c..214306745 100644 --- a/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -895,7 +895,7 @@ object messages { case class PkgDuplicateSymbol(existing: Symbol)(implicit ctx: Context) extends Message(33) { - val kind = "Duplicate Type" + val kind = "Duplicate Symbol" val msg = hl"trying to define package with same name as `$existing`" val explanation = "" } diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 22b5517dd..9343597a4 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -347,14 +347,13 @@ class Namer { typer: Typer => if ((existing is Package) && (pkgOwner eq existing.owner)) existing else { - // If the name exists as type we should unlink the existing name from the - // scope, issue an error and continue, as usual: + /** If there's already an existing type, then the package is a dup of this type */ val existingTpe = pkgOwner.info.decls.lookup(pid.name.toTypeName) if (existingTpe != NoSymbol) { ctx.error(PkgDuplicateSymbol(existingTpe), pid.pos) - pkgOwner.info.decls.openForMutations.unlink(existingTpe) + ctx.newCompletePackageSymbol(pkgOwner, (pid.name.asTermName.show + "$$package").toTermName).entered } - ctx.newCompletePackageSymbol(pkgOwner, pid.name.asTermName).entered + else ctx.newCompletePackageSymbol(pkgOwner, pid.name.asTermName).entered } } @@ -388,9 +387,10 @@ class Namer { typer: Typer => localCtx } - /** For all class definitions `stat` in `xstats`: If the companion class if not also defined - * in `xstats`, invalidate it by setting its info to NoType. - */ + /** For all class definitions `stat` in `xstats`: If the companion class if + * not also defined in `xstats`, invalidate it by setting its info to + * NoType. + */ def invalidateCompanions(pkg: Symbol, xstats: List[untpd.Tree])(implicit ctx: Context): Unit = { val definedNames = xstats collect { case stat: NameTree => stat.name } def invalidate(name: TypeName) = -- cgit v1.2.3