Skip to content

Invalidate companions of classes lifted by FlatMap #420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/dotty/tools/dotc/transform/RestoreScopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import Symbols._
import Scopes._
import collection.mutable
import TreeTransforms.MiniPhaseTransform
import SymDenotations._
import ast.Trees._
import NameOps._
import typer.Mode
import TreeTransforms.TransformerInfo

/** The preceding lambda lift and flatten phases move symbols to different scopes
Expand All @@ -19,16 +22,32 @@ class RestoreScopes extends MiniPhaseTransform with IdentityDenotTransformer { t
import ast.tpd._
override def phaseName = "restoreScopes"

private def invalidateUndefinedCompanions(pkg: ClassSymbol, cls: ClassSymbol)(implicit ctx: Context): Unit = {
val otherNames =
if (cls is Flags.Module)
List(cls.name.sourceModuleName, cls.name.stripModuleClassSuffix.toTypeName)
else
List(cls.name.toTermName, cls.name.moduleClassName)
for (otherName <- otherNames) {
val other = pkg.info.decl(otherName).asSymDenotation
if (other.exists && !other.isCompleted) other.markAbsent
}
}

override def transformTypeDef(tree: TypeDef)(implicit ctx: Context, info: TransformerInfo) = {
val TypeDef(_, impl: Template) = tree
//
val restoredDecls = newScope
for (stat <- impl.constr :: impl.body)
if (stat.isInstanceOf[MemberDef] && stat.symbol.exists)
restoredDecls.enter(stat.symbol)
val cls = tree.symbol.asClass
cls.owner.asClass.enter(cls)
// Enter class in enclosing package scope, in case it was an inner class before flatten.
// For top-level classes this does nothing.
val cls = tree.symbol.asClass
val pkg = cls.owner.asClass
pkg.enter(cls)
invalidateUndefinedCompanions(pkg, cls)(
ctx.withPhase(cls.initial.validFor.phaseId).addMode(Mode.FutureDefsOK))
val cinfo = cls.classInfo
tree.symbol.copySymDenotation(
info = cinfo.derivedClassInfo( // Dotty deviation: Cannot expand cinfo inline without a type error
Expand Down