aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-01-18 14:59:56 +0100
committerMartin Odersky <odersky@gmail.com>2014-01-18 15:00:08 +0100
commit559d25c88b39b7f2cac4a6c5b8431f8e0a62b56b (patch)
tree839dfe9e03c7d62d5a9c8d01f12fbc80ab12f6b8 /src
parenta0d6eedeb64d45af53a3cb93ab48b22855e3a61c (diff)
downloaddotty-559d25c88b39b7f2cac4a6c5b8431f8e0a62b56b.tar.gz
dotty-559d25c88b39b7f2cac4a6c5b8431f8e0a62b56b.tar.bz2
dotty-559d25c88b39b7f2cac4a6c5b8431f8e0a62b56b.zip
Invalidate companions of source-defined symbols
Without such invalidation, the previous classfile loader stays active, which will lead to confusion later on.
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/SymbolLoaders.scala4
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala21
2 files changed, 23 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala
index c66fcb656..60717bb82 100644
--- a/src/dotty/tools/dotc/core/SymbolLoaders.scala
+++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala
@@ -11,7 +11,7 @@ import java.io.IOException
import scala.compat.Platform.currentTime
import dotty.tools.io.{ ClassPath, AbstractFile }
import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, util.Positions._, Names._
-import StdNames._
+import StdNames._, NameOps._
import Decorators.StringDecorator
import pickling.ClassfileParser
@@ -278,7 +278,7 @@ class ClassfileLoader(val classfile: AbstractFile)(implicit val cctx: CondensedC
// as a class in scala.reflect and as a val in scala.reflect.package.
if (rootDenot is ModuleClass)
cctx.newClassSymbol(
- rootDenot.owner, rootDenot.name.asTypeName, Synthetic,
+ rootDenot.owner, rootDenot.name.stripModuleClassSuffix.asTypeName, Synthetic,
_ => NoType).classDenot
else
cctx.newModuleSymbol(
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 952c7997e..ece9f51a7 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -265,6 +265,26 @@ class Namer { typer: Typer =>
localCtx
}
+ /** `stat` is a definition in package `pkg`. If `stat` has a potential companion,
+ * invalidate the companion symbol by setting its info to NoType. (If the companion
+ * does in fact exist it the info will be immediately reset to a completer
+ * by the subsequent index operation).
+ */
+ private def invalidateCompanion(pkg: Symbol, stat: untpd.Tree)(implicit ctx: Context) = {
+ def invalidate(name: Name) =
+ pkg.info.decl(name).alternatives foreach { member =>
+ if (member.symbol.isClass && !(member.symbol is Package))
+ member.symbol.info = NoType
+ }
+ stat match {
+ case stat: TypeDef if stat.isClassDef =>
+ invalidate(stat.name.moduleClassName)
+ case stat: ModuleDef =>
+ invalidate(stat.name.toTypeName)
+ case _ =>
+ }
+ }
+
/** Expand tree and create top-level symbols for statement and enter them into symbol table */
def index(stat: Tree)(implicit ctx: Context): Context = {
expand(stat)
@@ -277,6 +297,7 @@ class Namer { typer: Typer =>
def indexExpanded(stat: Tree)(implicit ctx: Context): Context = expanded(stat) match {
case pcl: PackageDef =>
val pkg = createPackageSymbol(pcl.pid)
+ pcl.stats foreach (invalidateCompanion(pkg, _))
index(pcl.stats)(ctx.fresh.withOwner(pkg.moduleClass))
ctx
case imp: Import =>