diff options
author | Martin Odersky <odersky@gmail.com> | 2014-02-07 15:12:19 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-02-07 15:12:19 +0100 |
commit | c643ff5a38812e00ea7d6fbae94114beacd14ecf (patch) | |
tree | 95b66e159bf87b3faf753d171e133f82c6e595d5 /src | |
parent | 5bed5bdd1bb377e9a177a2be635b391bfc0f168e (diff) | |
download | dotty-c643ff5a38812e00ea7d6fbae94114beacd14ecf.tar.gz dotty-c643ff5a38812e00ea7d6fbae94114beacd14ecf.tar.bz2 dotty-c643ff5a38812e00ea7d6fbae94114beacd14ecf.zip |
Invalidate companions after indexing.
Invalidating them before indexing means symbols are touched before a new version is entered, which leads to "compiled twice" errors.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 6583b4c0b..e79bd32c1 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -273,22 +273,19 @@ 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). + /** 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. */ - 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 + 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) = + if (!(definedNames contains name)) { + val member = pkg.info.decl(name).asSymDenotation + if (member.isClass && !(member is Package)) member.info = NoType } - stat match { + xstats foreach { case stat: TypeDef if stat.isClassDef => invalidate(stat.name.moduleClassName) - case stat: ModuleDef => - invalidate(stat.name.toTypeName) case _ => } } @@ -305,8 +302,8 @@ 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)) + invalidateCompanions(pkg, Trees.flatten(pcl.stats map expanded)) ctx case imp: Import => importContext(createSymbol(imp), imp.selectors) |