aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/transform/RestoreScopes.scala23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/transform/RestoreScopes.scala b/src/dotty/tools/dotc/transform/RestoreScopes.scala
index 8a6bb15ba..7c84e8749 100644
--- a/src/dotty/tools/dotc/transform/RestoreScopes.scala
+++ b/src/dotty/tools/dotc/transform/RestoreScopes.scala
@@ -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
@@ -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