Skip to content

Commit cf1a31c

Browse files
committed
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
1 parent 5d257b7 commit cf1a31c

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ object messages {
895895

896896
case class PkgDuplicateSymbol(existing: Symbol)(implicit ctx: Context)
897897
extends Message(33) {
898-
val kind = "Duplicate Type"
898+
val kind = "Duplicate Symbol"
899899
val msg = hl"trying to define package with same name as `$existing`"
900900
val explanation = ""
901901
}

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,14 +347,13 @@ class Namer { typer: Typer =>
347347

348348
if ((existing is Package) && (pkgOwner eq existing.owner)) existing
349349
else {
350-
// If the name exists as type we should unlink the existing name from the
351-
// scope, issue an error and continue, as usual:
350+
/** If there's already an existing type, then the package is a dup of this type */
352351
val existingTpe = pkgOwner.info.decls.lookup(pid.name.toTypeName)
353352
if (existingTpe != NoSymbol) {
354353
ctx.error(PkgDuplicateSymbol(existingTpe), pid.pos)
355-
pkgOwner.info.decls.openForMutations.unlink(existingTpe)
354+
ctx.newCompletePackageSymbol(pkgOwner, (pid.name.asTermName.show + "$$package").toTermName).entered
356355
}
357-
ctx.newCompletePackageSymbol(pkgOwner, pid.name.asTermName).entered
356+
else ctx.newCompletePackageSymbol(pkgOwner, pid.name.asTermName).entered
358357
}
359358
}
360359

@@ -388,9 +387,10 @@ class Namer { typer: Typer =>
388387
localCtx
389388
}
390389

391-
/** For all class definitions `stat` in `xstats`: If the companion class if not also defined
392-
* in `xstats`, invalidate it by setting its info to NoType.
393-
*/
390+
/** For all class definitions `stat` in `xstats`: If the companion class if
391+
* not also defined in `xstats`, invalidate it by setting its info to
392+
* NoType.
393+
*/
394394
def invalidateCompanions(pkg: Symbol, xstats: List[untpd.Tree])(implicit ctx: Context): Unit = {
395395
val definedNames = xstats collect { case stat: NameTree => stat.name }
396396
def invalidate(name: TypeName) =

0 commit comments

Comments
 (0)