aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Namer.scala
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-11-14 17:10:54 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-11-17 10:04:23 +0100
commit6a398a2d551534157f14c4bba103c3dff9b85c18 (patch)
tree3fac284ff9d3dbb9a3fc149a615971576fbd8106 /src/dotty/tools/dotc/typer/Namer.scala
parentadb37eee8974be841ff5eef2655c23394c05badb (diff)
downloaddotty-6a398a2d551534157f14c4bba103c3dff9b85c18.tar.gz
dotty-6a398a2d551534157f14c4bba103c3dff9b85c18.tar.bz2
dotty-6a398a2d551534157f14c4bba103c3dff9b85c18.zip
Unlink type when entering clashing package
Here we unlink the existing type that clashes with the package to be entered into the symbol table, issue an error and the proceed to enter the rest of the symbols. My concern with this approach is what happens during typechecking if other things reference the unlinked type.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Namer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 687de1e7a..22b5517dd 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -21,6 +21,7 @@ import Inferencing._
import transform.ValueClasses._
import TypeApplications._
import language.implicitConversions
+import reporting.diagnostic.messages._
trait NamerContextOps { this: Context =>
@@ -264,7 +265,7 @@ class Namer { typer: Typer =>
def preExisting = ctx.effectiveScope.lookup(name)
if (ctx.owner is PackageClass)
if (preExisting.isDefinedInCurrentRun)
- errorName(s"${preExisting.showLocated} is compiled twice")
+ errorName(s"${preExisting.showLocated} has already been compiled\nonce during this run")
else name
else
if ((!ctx.owner.isClass || name.isTypeName) && preExisting.exists)
@@ -343,8 +344,18 @@ class Namer { typer: Typer =>
case Select(qual: RefTree, _) => createPackageSymbol(qual).moduleClass
}
val existing = pkgOwner.info.decls.lookup(pid.name)
+
if ((existing is Package) && (pkgOwner eq existing.owner)) existing
- else ctx.newCompletePackageSymbol(pkgOwner, pid.name.asTermName).entered
+ else {
+ // If the name exists as type we should unlink the existing name from the
+ // scope, issue an error and continue, as usual:
+ 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).entered
+ }
}
/** Expand tree and store in `expandedTree` */