@@ -8,7 +8,10 @@ import Symbols._
8
8
import Scopes ._
9
9
import collection .mutable
10
10
import TreeTransforms .MiniPhaseTransform
11
+ import SymDenotations ._
11
12
import ast .Trees ._
13
+ import NameOps ._
14
+ import typer .Mode
12
15
import TreeTransforms .TransformerInfo
13
16
14
17
/** The preceding lambda lift and flatten phases move symbols to different scopes
@@ -19,16 +22,32 @@ class RestoreScopes extends MiniPhaseTransform with IdentityDenotTransformer { t
19
22
import ast .tpd ._
20
23
override def phaseName = " restoreScopes"
21
24
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
+
22
37
override def transformTypeDef (tree : TypeDef )(implicit ctx : Context , info : TransformerInfo ) = {
23
38
val TypeDef (_, impl : Template ) = tree
39
+ //
24
40
val restoredDecls = newScope
25
41
for (stat <- impl.constr :: impl.body)
26
42
if (stat.isInstanceOf [MemberDef ] && stat.symbol.exists)
27
43
restoredDecls.enter(stat.symbol)
28
- val cls = tree.symbol.asClass
29
- cls.owner.asClass.enter(cls)
30
44
// Enter class in enclosing package scope, in case it was an inner class before flatten.
31
45
// 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 ))
32
51
val cinfo = cls.classInfo
33
52
tree.symbol.copySymDenotation(
34
53
info = cinfo.derivedClassInfo( // Dotty deviation: Cannot expand cinfo inline without a type error
0 commit comments