@@ -8,7 +8,10 @@ import Symbols._
88import Scopes ._
99import collection .mutable
1010import TreeTransforms .MiniPhaseTransform
11+ import SymDenotations ._
1112import ast .Trees ._
13+ import NameOps ._
14+ import typer .Mode
1215import TreeTransforms .TransformerInfo
1316
1417/** The preceding lambda lift and flatten phases move symbols to different scopes
@@ -19,16 +22,32 @@ class RestoreScopes extends MiniPhaseTransform with IdentityDenotTransformer { t
1922 import ast .tpd ._
2023 override def phaseName = " restoreScopes"
2124
25+ private def invalidateUndefinedCompanions (pkg : ClassSymbol , cls : ClassSymbol )(implicit ctx : Context ): Unit = {
26+ val otherNames =
27+ if (cls is Flags .Module )
28+ List (cls.name.sourceModuleName, cls.name.stripModuleClassSuffix.toTypeName)
29+ else
30+ List (cls.name.toTermName, cls.name.moduleClassName)
31+ for (otherName <- otherNames) {
32+ val other = pkg.info.decl(otherName).asSymDenotation
33+ if (other.exists && ! other.isCompleted) other.markAbsent
34+ }
35+ }
36+
2237 override def transformTypeDef (tree : TypeDef )(implicit ctx : Context , info : TransformerInfo ) = {
2338 val TypeDef (_, impl : Template ) = tree
39+ //
2440 val restoredDecls = newScope
2541 for (stat <- impl.constr :: impl.body)
2642 if (stat.isInstanceOf [MemberDef ] && stat.symbol.exists)
2743 restoredDecls.enter(stat.symbol)
28- val cls = tree.symbol.asClass
29- cls.owner.asClass.enter(cls)
3044 // Enter class in enclosing package scope, in case it was an inner class before flatten.
3145 // For top-level classes this does nothing.
46+ val cls = tree.symbol.asClass
47+ val pkg = cls.owner.asClass
48+ pkg.enter(cls)
49+ invalidateUndefinedCompanions(pkg, cls)(
50+ ctx.withPhase(cls.initial.validFor.phaseId).addMode(Mode .FutureDefsOK ))
3251 val cinfo = cls.classInfo
3352 tree.symbol.copySymDenotation(
3453 info = cinfo.derivedClassInfo( // Dotty deviation: Cannot expand cinfo inline without a type error
0 commit comments