From 559d25c88b39b7f2cac4a6c5b8431f8e0a62b56b Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 18 Jan 2014 14:59:56 +0100 Subject: Invalidate companions of source-defined symbols Without such invalidation, the previous classfile loader stays active, which will lead to confusion later on. --- src/dotty/tools/dotc/core/SymbolLoaders.scala | 4 ++-- src/dotty/tools/dotc/typer/Namer.scala | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'src') 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 => -- cgit v1.2.3